init
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<Bindings>
|
||||
<Binding name="Raid Marker" runOnUp="true" header="ELVUI">
|
||||
RaidMark_HotkeyPressed(keystate)
|
||||
</Binding>
|
||||
<Binding name="Farm Mode" runOnUp="false">
|
||||
FarmMode()
|
||||
</Binding>
|
||||
<Binding name="Toggle Chat (Left)" runOnUp="false">
|
||||
HideLeftChat()
|
||||
</Binding>
|
||||
<Binding name="Toggle Chat (Right)" runOnUp="false">
|
||||
HideRightChat()
|
||||
</Binding>
|
||||
<Binding name="Toggle Chat (Both)" runOnUp="false">
|
||||
HideBothChat()
|
||||
</Binding>
|
||||
</Bindings>
|
||||
@@ -0,0 +1,260 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
|
||||
--Lua functions
|
||||
local _G = _G
|
||||
local wipe, date = wipe, date
|
||||
local format, select, type, ipairs, pairs = format, select, type, ipairs, pairs
|
||||
local strmatch, strfind, tonumber, tostring = strmatch, strfind, tonumber, tostring
|
||||
--WoW API / Variables
|
||||
local GetCVarBool = GetCVarBool
|
||||
local GetFunctionCPUUsage = GetFunctionCPUUsage
|
||||
local RequestBattlefieldScoreData = RequestBattlefieldScoreData
|
||||
local UnitGroupRolesAssigned = UnitGroupRolesAssigned
|
||||
local UnitHasVehicleUI = UnitHasVehicleUI
|
||||
local IsInInstance = IsInInstance
|
||||
|
||||
E.Role = "Melee" -- TODO: Load locally, or save per specialization.
|
||||
|
||||
do -- other non-english locales require this
|
||||
E.UnlocalizedClasses = {}
|
||||
for k, v in pairs(_G.LOCALIZED_CLASS_NAMES_MALE) do E.UnlocalizedClasses[v] = k end
|
||||
for k, v in pairs(_G.LOCALIZED_CLASS_NAMES_FEMALE) do E.UnlocalizedClasses[v] = k end
|
||||
|
||||
function E:UnlocalizedClassName(className)
|
||||
return (className and className ~= "") and E.UnlocalizedClasses[className]
|
||||
end
|
||||
end
|
||||
|
||||
function E:ScanTooltipTextures(clean, grabTextures)
|
||||
local textures
|
||||
for i = 1, 10 do
|
||||
local tex = _G["ElvUI_ScanTooltipTexture"..i]
|
||||
local texture = tex and tex:GetTexture()
|
||||
if texture then
|
||||
if grabTextures then
|
||||
if not textures then textures = {} end
|
||||
textures[i] = texture
|
||||
end
|
||||
if clean then
|
||||
tex:SetTexture()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return textures
|
||||
end
|
||||
|
||||
function E:GetPlayerRole()
|
||||
local isTank, isHealer, isDamage = UnitGroupRolesAssigned("player")
|
||||
|
||||
if isTank or isHealer or isDamage then
|
||||
return isTank and "TANK" or isHealer and "HEALER" or isDamage and "DAMAGER"
|
||||
else
|
||||
return "DAMAGER" -- Assume dps role; Nothing better for ascension.
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
--local Masque = E.Libs.Masque
|
||||
local LBFGroupToTableElement = {
|
||||
["ActionBars"] = "actionbar",
|
||||
["Auras"] = "auras"
|
||||
}
|
||||
|
||||
function E:LBFCallback(SkinID, _, _, Group)
|
||||
if not E.private then return end
|
||||
|
||||
local element = LBFGroupToTableElement[Group]
|
||||
if element then
|
||||
if E.private[element].lbf.enable then
|
||||
E.private[element].lbf.skin = SkinID
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if LBF then
|
||||
LBF:RegisterSkinCallback("ElvUI", E.LBFCallback, E)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local CPU_USAGE = {}
|
||||
local function CompareCPUDiff(showall, minCalls)
|
||||
local greatestUsage, greatestCalls, greatestName, newName, newFunc
|
||||
local greatestDiff, lastModule, mod, usage, calls, diff = 0
|
||||
|
||||
for name, oldUsage in pairs(CPU_USAGE) do
|
||||
newName, newFunc = strmatch(name, "^([^:]+):(.+)$")
|
||||
if not newFunc then
|
||||
E:Print("CPU_USAGE:", name, newFunc)
|
||||
else
|
||||
if newName ~= lastModule then
|
||||
mod = E:GetModule(newName, true) or E
|
||||
lastModule = newName
|
||||
end
|
||||
usage, calls = GetFunctionCPUUsage(mod[newFunc], true)
|
||||
diff = usage - oldUsage
|
||||
if showall and (calls > minCalls) then
|
||||
E:Print("Name("..name..") Calls("..calls..") Diff("..(diff > 0 and format("%.3f", diff) or 0)..")")
|
||||
end
|
||||
if (diff > greatestDiff) and calls > minCalls then
|
||||
greatestName, greatestUsage, greatestCalls, greatestDiff = name, usage, calls, diff
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if greatestName then
|
||||
E:Print(greatestName.." had the CPU usage of: "..(greatestUsage > 0 and format("%.3f", greatestUsage) or 0).."ms. And has been called "..greatestCalls.." times.")
|
||||
else
|
||||
E:Print("CPU Usage: No CPU Usage differences found.")
|
||||
end
|
||||
|
||||
wipe(CPU_USAGE)
|
||||
end
|
||||
|
||||
function E:GetTopCPUFunc(msg)
|
||||
if not GetCVarBool("scriptProfile") then
|
||||
E:Print("For `/cpuusage` to work, you need to enable script profiling via: `/console scriptProfile 1` then reload. Disable after testing by setting it back to 0.")
|
||||
return
|
||||
end
|
||||
|
||||
local module, showall, delay, minCalls = strmatch(msg, "^(%S+)%s*(%S*)%s*(%S*)%s*(.*)$")
|
||||
local checkCore, mod = (not module or module == "") and "E"
|
||||
|
||||
showall = (showall == "true" and true) or false
|
||||
delay = (delay == "nil" and nil) or tonumber(delay) or 5
|
||||
minCalls = (minCalls == "nil" and nil) or tonumber(minCalls) or 15
|
||||
|
||||
wipe(CPU_USAGE)
|
||||
if module == "all" then
|
||||
for moduName, modu in pairs(self.modules) do
|
||||
for funcName, func in pairs(modu) do
|
||||
if (funcName ~= "GetModule") and (type(func) == "function") then
|
||||
CPU_USAGE[moduName..":"..funcName] = GetFunctionCPUUsage(func, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if not checkCore then
|
||||
mod = self:GetModule(module, true)
|
||||
if not mod then
|
||||
self:Print(module.." not found, falling back to checking core.")
|
||||
mod, checkCore = self, "E"
|
||||
end
|
||||
else
|
||||
mod = self
|
||||
end
|
||||
for name, func in pairs(mod) do
|
||||
if (name ~= "GetModule") and type(func) == "function" then
|
||||
CPU_USAGE[(checkCore or module)..":"..name] = GetFunctionCPUUsage(func, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self:Delay(delay, CompareCPUDiff, showall, minCalls)
|
||||
self:Print("Calculating CPU Usage differences (module: "..(checkCore or module)..", showall: "..tostring(showall)..", minCalls: "..tostring(minCalls)..", delay: "..tostring(delay)..")")
|
||||
end
|
||||
end
|
||||
|
||||
function E:RegisterObjectForVehicleLock(object, originalParent)
|
||||
if not object or not originalParent then
|
||||
E:Print("Error. Usage: RegisterObjectForVehicleLock(object, originalParent)")
|
||||
return
|
||||
end
|
||||
|
||||
object = _G[object] or object
|
||||
--Entering/Exiting vehicles will often happen in combat.
|
||||
--For this reason we cannot allow protected objects.
|
||||
if object.IsProtected and object:IsProtected() then
|
||||
E:Print("Error. Object is protected and cannot be changed in combat.")
|
||||
return
|
||||
end
|
||||
|
||||
--Check if we are already in a vehicles
|
||||
if UnitHasVehicleUI("player") then
|
||||
object:SetParent(E.HiddenFrame)
|
||||
end
|
||||
|
||||
--Add object to table
|
||||
E.VehicleLocks[object] = originalParent
|
||||
end
|
||||
|
||||
function E:UnregisterObjectForVehicleLock(object)
|
||||
if not object then
|
||||
E:Print("Error. Usage: UnregisterObjectForVehicleLock(object)")
|
||||
return
|
||||
end
|
||||
|
||||
object = _G[object] or object
|
||||
--Check if object was registered to begin with
|
||||
if not E.VehicleLocks[object] then return end
|
||||
|
||||
--Change parent of object back to original parent
|
||||
local originalParent = E.VehicleLocks[object]
|
||||
if originalParent then
|
||||
object:SetParent(originalParent)
|
||||
end
|
||||
|
||||
--Remove object from table
|
||||
E.VehicleLocks[object] = nil
|
||||
end
|
||||
|
||||
function E:EnterVehicleHideFrames(_, unit)
|
||||
if unit ~= "player" then return end
|
||||
|
||||
for object in pairs(E.VehicleLocks) do
|
||||
object:SetParent(E.HiddenFrame)
|
||||
end
|
||||
end
|
||||
|
||||
function E:ExitVehicleShowFrames(_, unit)
|
||||
if unit ~= "player" then return end
|
||||
|
||||
for object, originalParent in pairs(E.VehicleLocks) do
|
||||
object:SetParent(originalParent)
|
||||
end
|
||||
end
|
||||
|
||||
function E:RequestBGInfo()
|
||||
RequestBattlefieldScoreData()
|
||||
end
|
||||
|
||||
function E:PLAYER_ENTERING_WORLD()
|
||||
if not self.MediaUpdated then
|
||||
self:UpdateMedia()
|
||||
self.MediaUpdated = true
|
||||
end
|
||||
|
||||
local _, instanceType = IsInInstance()
|
||||
if instanceType == "pvp" then
|
||||
self.BGTimer = self:ScheduleRepeatingTimer("RequestBGInfo", 5)
|
||||
self:RequestBGInfo()
|
||||
elseif self.BGTimer then
|
||||
self:CancelTimer(self.BGTimer)
|
||||
self.BGTimer = nil
|
||||
end
|
||||
end
|
||||
|
||||
function E:PLAYER_LEVEL_UP(_, level)
|
||||
E.mylevel = level
|
||||
end
|
||||
|
||||
function E:LoadAPI()
|
||||
self:RegisterEvent("PLAYER_LEVEL_UP")
|
||||
self:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
self:RegisterEvent("UNIT_ENTERED_VEHICLE", "EnterVehicleHideFrames")
|
||||
self:RegisterEvent("UNIT_EXITED_VEHICLE", "ExitVehicleShowFrames")
|
||||
self:RegisterEvent("UI_SCALE_CHANGED", "PixelScaleChanged")
|
||||
|
||||
do -- setup cropIcon texCoords
|
||||
local opt = E.db.general.cropIcon
|
||||
local modifier = 0.04 * opt
|
||||
for i, v in ipairs(E.TexCoords) do
|
||||
if i % 2 == 0 then
|
||||
E.TexCoords[i] = v - modifier
|
||||
else
|
||||
E.TexCoords[i] = v + modifier
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,294 @@
|
||||
------------------------------------------------------------------------
|
||||
-- Animation Functions
|
||||
------------------------------------------------------------------------
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
|
||||
--Lua functions
|
||||
local random, next, unpack, strsub = random, next, unpack, strsub
|
||||
--WoW API / Variables
|
||||
|
||||
E.AnimShake = {{-9,7,-7,12}, {-5,9,-9,5}, {-5,7,-7,5}, {-9,9,-9,9}, {-5,7,-7,5}, {-9,7,-9,5}}
|
||||
E.AnimShakeH = {-5,5,-2,5,-2,5}
|
||||
|
||||
function E:FlashLoopFinished(requested)
|
||||
if not requested then self:Play() end
|
||||
end
|
||||
|
||||
function E:RandomAnimShake(index)
|
||||
local s = E.AnimShake[index]
|
||||
return random(s[1], s[2]), random(s[3], s[4])
|
||||
end
|
||||
|
||||
function E:SetUpAnimGroup(obj, Type, ...)
|
||||
if not Type then Type = "Flash" end
|
||||
|
||||
if strsub(Type, 1, 5) == "Flash" then
|
||||
obj.anim = obj:CreateAnimationGroup("Flash")
|
||||
obj.anim.fadein = obj.anim:CreateAnimation("ALPHA", "FadeIn")
|
||||
obj.anim.fadein:SetChange(1)
|
||||
obj.anim.fadein:SetOrder(2)
|
||||
|
||||
obj.anim.fadeout = obj.anim:CreateAnimation("ALPHA", "FadeOut")
|
||||
obj.anim.fadeout:SetChange(-1)
|
||||
obj.anim.fadeout:SetOrder(1)
|
||||
|
||||
if Type == "FlashLoop" then
|
||||
obj.anim:SetScript("OnFinished", E.FlashLoopFinished)
|
||||
end
|
||||
elseif strsub(Type, 1, 5) == "Shake" then
|
||||
local shake = obj:CreateAnimationGroup(Type)
|
||||
shake:SetLooping("REPEAT")
|
||||
shake.path = shake:CreateAnimation("Path")
|
||||
|
||||
if Type == "Shake" then
|
||||
shake.path:SetDuration(0.7)
|
||||
obj.shake = shake
|
||||
elseif Type == "ShakeH" then
|
||||
shake.path:SetDuration(2)
|
||||
obj.shakeh = shake
|
||||
end
|
||||
|
||||
for i = 1, 6 do
|
||||
shake.path[i] = shake.path:CreateControlPoint()
|
||||
|
||||
if Type == "Shake" then
|
||||
shake.path[i]:SetOffset(E:RandomAnimShake(i))
|
||||
else
|
||||
shake.path[i]:SetOffset(E.AnimShakeH[i], 0)
|
||||
end
|
||||
end
|
||||
shake.path[1]:SetOrder(1)
|
||||
shake.path[2]:SetOrder(2)
|
||||
shake.path[3]:SetOrder(3)
|
||||
shake.path[4]:SetOrder(4)
|
||||
shake.path[5]:SetOrder(5)
|
||||
shake.path[6]:SetOrder(6)
|
||||
else
|
||||
local x, y, duration, customName = ...
|
||||
if not customName then customName = "anim" end
|
||||
|
||||
local anim = obj:CreateAnimationGroup("Move_In")
|
||||
obj[customName] = anim
|
||||
|
||||
anim.in1 = anim:CreateAnimation("Translation")
|
||||
anim.in1:SetDuration(0)
|
||||
anim.in1:SetOrder(1)
|
||||
anim.in1:SetOffset(E:Scale(x), E:Scale(y))
|
||||
|
||||
anim.in2 = anim:CreateAnimation("Translation")
|
||||
anim.in2:SetDuration(duration)
|
||||
anim.in2:SetOrder(2)
|
||||
anim.in2:SetSmoothing("OUT")
|
||||
anim.in2:SetOffset(E:Scale(-x), E:Scale(-y))
|
||||
|
||||
anim.out1 = obj:CreateAnimationGroup("Move_Out")
|
||||
anim.out1:SetScript("OnFinished", function() obj:Hide() end)
|
||||
|
||||
anim.out2 = anim.out1:CreateAnimation("Translation")
|
||||
anim.out2:SetDuration(duration)
|
||||
anim.out2:SetOrder(1)
|
||||
anim.out2:SetSmoothing("IN")
|
||||
anim.out2:SetOffset(E:Scale(x), E:Scale(y))
|
||||
end
|
||||
end
|
||||
|
||||
function E:Shake(obj)
|
||||
if not obj.shake then
|
||||
E:SetUpAnimGroup(obj, "Shake")
|
||||
end
|
||||
|
||||
obj.shake:Play()
|
||||
end
|
||||
|
||||
function E:StopShake(obj)
|
||||
if obj.shake then
|
||||
obj.shake:Finish()
|
||||
end
|
||||
end
|
||||
|
||||
function E:ShakeHorizontal(obj)
|
||||
if not obj.shakeh then
|
||||
E:SetUpAnimGroup(obj, "ShakeH")
|
||||
end
|
||||
|
||||
obj.shakeh:Play()
|
||||
end
|
||||
|
||||
function E:StopShakeHorizontal(obj)
|
||||
if obj.shakeh then
|
||||
obj.shakeh:Finish()
|
||||
end
|
||||
end
|
||||
|
||||
function E:Flash(obj, duration, loop)
|
||||
if not obj.anim then
|
||||
E:SetUpAnimGroup(obj, loop and "FlashLoop" or "Flash")
|
||||
end
|
||||
|
||||
if not obj.anim:IsPlaying() then
|
||||
obj.anim.fadein:SetDuration(duration)
|
||||
obj.anim.fadeout:SetDuration(duration)
|
||||
obj.anim:Play()
|
||||
end
|
||||
end
|
||||
|
||||
function E:StopFlash(obj)
|
||||
if obj.anim and obj.anim:IsPlaying() then
|
||||
obj.anim:Stop()
|
||||
end
|
||||
end
|
||||
|
||||
function E:SlideIn(obj, customName)
|
||||
if not customName then customName = "anim" end
|
||||
if not obj[customName] then return end
|
||||
|
||||
obj[customName].out1:Stop()
|
||||
obj[customName]:Play()
|
||||
obj:Show()
|
||||
end
|
||||
|
||||
function E:SlideOut(obj, customName)
|
||||
if not customName then customName = "anim" end
|
||||
if not obj[customName] then return end
|
||||
|
||||
obj[customName]:Finish()
|
||||
obj[customName]:Stop()
|
||||
obj[customName].out1:Play()
|
||||
end
|
||||
|
||||
local FADEFRAMES, FADEMANAGER = {}, CreateFrame("FRAME")
|
||||
FADEMANAGER.delay = 0.05
|
||||
|
||||
function E:UIFrameFade_OnUpdate(elapsed)
|
||||
FADEMANAGER.timer = (FADEMANAGER.timer or 0) + elapsed
|
||||
|
||||
if FADEMANAGER.timer > FADEMANAGER.delay then
|
||||
FADEMANAGER.timer = 0
|
||||
|
||||
for frame, info in next, FADEFRAMES do
|
||||
-- Reset the timer if there isn't one, this is just an internal counter
|
||||
if frame:IsVisible() then
|
||||
info.fadeTimer = (info.fadeTimer or 0) + (elapsed + FADEMANAGER.delay)
|
||||
else
|
||||
info.fadeTimer = info.timeToFade + 1
|
||||
end
|
||||
|
||||
-- If the fadeTimer is less then the desired fade time then set the alpha otherwise hold the fade state, call the finished function, or just finish the fade
|
||||
if info.fadeTimer < info.timeToFade then
|
||||
if info.mode == "IN" then
|
||||
frame:SetAlpha((info.fadeTimer / info.timeToFade) * info.diffAlpha + info.startAlpha)
|
||||
else
|
||||
frame:SetAlpha(((info.timeToFade - info.fadeTimer) / info.timeToFade) * info.diffAlpha + info.endAlpha)
|
||||
end
|
||||
else
|
||||
frame:SetAlpha(info.endAlpha)
|
||||
|
||||
-- If there is a fadeHoldTime then wait until its passed to continue on
|
||||
if info.fadeHoldTime and info.fadeHoldTime > 0 then
|
||||
info.fadeHoldTime = info.fadeHoldTime - elapsed
|
||||
else
|
||||
-- Complete the fade and call the finished function if there is one
|
||||
E:UIFrameFadeRemoveFrame(frame)
|
||||
|
||||
if info.finishedFunc then
|
||||
if info.finishedArgs then
|
||||
info.finishedFunc(unpack(info.finishedArgs))
|
||||
else -- optional method
|
||||
info.finishedFunc(info.finishedArg1, info.finishedArg2, info.finishedArg3, info.finishedArg4, info.finishedArg5)
|
||||
end
|
||||
|
||||
if not info.finishedFuncKeep then
|
||||
info.finishedFunc = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not next(FADEFRAMES) then
|
||||
FADEMANAGER:SetScript("OnUpdate", nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Generic fade function
|
||||
function E:UIFrameFade(frame, info)
|
||||
if not frame then return end
|
||||
|
||||
frame.fadeInfo = info
|
||||
|
||||
if not info.mode then
|
||||
info.mode = "IN"
|
||||
end
|
||||
|
||||
if info.mode == "IN" then
|
||||
if not info.startAlpha then info.startAlpha = 0 end
|
||||
if not info.endAlpha then info.endAlpha = 1 end
|
||||
if not info.diffAlpha then info.diffAlpha = info.endAlpha - info.startAlpha end
|
||||
else
|
||||
if not info.startAlpha then info.startAlpha = 1 end
|
||||
if not info.endAlpha then info.endAlpha = 0 end
|
||||
if not info.diffAlpha then info.diffAlpha = info.startAlpha - info.endAlpha end
|
||||
end
|
||||
|
||||
frame:SetAlpha(info.startAlpha)
|
||||
|
||||
if not frame:IsProtected() then
|
||||
frame:Show()
|
||||
end
|
||||
|
||||
if not FADEFRAMES[frame] then
|
||||
FADEFRAMES[frame] = info -- read below comment
|
||||
FADEMANAGER:SetScript("OnUpdate", E.UIFrameFade_OnUpdate)
|
||||
else
|
||||
FADEFRAMES[frame] = info -- keep these both, we need this updated in the event its changed to another ref from a plugin or sth, don't move it up!
|
||||
end
|
||||
end
|
||||
|
||||
-- Convenience function to do a simple fade in
|
||||
function E:UIFrameFadeIn(frame, timeToFade, startAlpha, endAlpha)
|
||||
if not frame then return end
|
||||
|
||||
if frame.FadeObject then
|
||||
frame.FadeObject.fadeTimer = nil
|
||||
else
|
||||
frame.FadeObject = {}
|
||||
end
|
||||
|
||||
frame.FadeObject.mode = "IN"
|
||||
frame.FadeObject.timeToFade = timeToFade
|
||||
frame.FadeObject.startAlpha = startAlpha
|
||||
frame.FadeObject.endAlpha = endAlpha
|
||||
frame.FadeObject.diffAlpha = endAlpha - startAlpha
|
||||
|
||||
E:UIFrameFade(frame, frame.FadeObject)
|
||||
end
|
||||
|
||||
-- Convenience function to do a simple fade out
|
||||
function E:UIFrameFadeOut(frame, timeToFade, startAlpha, endAlpha)
|
||||
if not frame then return end
|
||||
|
||||
if frame.FadeObject then
|
||||
frame.FadeObject.fadeTimer = nil
|
||||
else
|
||||
frame.FadeObject = {}
|
||||
end
|
||||
|
||||
frame.FadeObject.mode = "OUT"
|
||||
frame.FadeObject.timeToFade = timeToFade
|
||||
frame.FadeObject.startAlpha = startAlpha
|
||||
frame.FadeObject.endAlpha = endAlpha
|
||||
frame.FadeObject.diffAlpha = startAlpha - endAlpha
|
||||
|
||||
E:UIFrameFade(frame, frame.FadeObject)
|
||||
end
|
||||
|
||||
function E:UIFrameFadeRemoveFrame(frame)
|
||||
if frame and FADEFRAMES[frame] then
|
||||
if frame.FadeObject then
|
||||
frame.FadeObject.fadeTimer = nil
|
||||
end
|
||||
|
||||
FADEFRAMES[frame] = nil
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,369 @@
|
||||
--[[
|
||||
Collection of previous april fools pranks
|
||||
|
||||
Harlem Shake: Try it out with the command /harlemshake
|
||||
Hello Kitty: Try it out with the command /hellokitty (pay attention to the popups, read what it says)
|
||||
]]
|
||||
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local UF = E:GetModule("UnitFrames")
|
||||
local AB = E:GetModule("ActionBars")
|
||||
|
||||
--Lua functions
|
||||
local _G = _G
|
||||
local pairs = pairs
|
||||
local twipe, tinsert = wipe, tinsert
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local DoEmote = DoEmote
|
||||
local GetCVar, SetCVar = GetCVar, SetCVar
|
||||
local PlayMusic, StopMusic = PlayMusic, StopMusic
|
||||
local SendChatMessage = SendChatMessage
|
||||
local NUM_PET_ACTION_SLOTS = NUM_PET_ACTION_SLOTS
|
||||
|
||||
--Harlem Shake (Activate with command: /harlemshake)
|
||||
--People really seemed to like this one. We got a lot of positive responses.
|
||||
do
|
||||
function E:StopHarlemShake()
|
||||
E.isMassiveShaking = nil
|
||||
StopMusic()
|
||||
SetCVar("Sound_EnableAllSound", self.oldEnableAllSound)
|
||||
SetCVar("Sound_EnableMusic", self.oldEnableMusic)
|
||||
|
||||
self:StopShakeHorizontal(ElvUI_StaticPopup1)
|
||||
for _, object in pairs(self.massiveShakeObjects) do
|
||||
if object then
|
||||
self:StopShake(object)
|
||||
end
|
||||
end
|
||||
|
||||
if E.massiveShakeTimer then
|
||||
E:CancelTimer(E.massiveShakeTimer)
|
||||
end
|
||||
|
||||
E.global.aprilFools = true
|
||||
E:StaticPopup_Hide("HARLEM_SHAKE")
|
||||
twipe(self.massiveShakeObjects)
|
||||
DoEmote("Dance")
|
||||
end
|
||||
|
||||
function E:DoTheHarlemShake()
|
||||
E.isMassiveShaking = true
|
||||
ElvUI_StaticPopup1Button1:Enable()
|
||||
|
||||
for _, object in pairs(self.massiveShakeObjects) do
|
||||
if object and object:IsShown() then
|
||||
self:Shake(object)
|
||||
end
|
||||
end
|
||||
|
||||
E.massiveShakeTimer = E:ScheduleTimer("StopHarlemShake", 42.5)
|
||||
SendChatMessage("DO THE HARLEM SHAKE!", "YELL")
|
||||
end
|
||||
|
||||
function E:BeginHarlemShake()
|
||||
DoEmote("Dance")
|
||||
ElvUI_StaticPopup1Button1:Disable()
|
||||
self:ShakeHorizontal(ElvUI_StaticPopup1)
|
||||
self.oldEnableAllSound = GetCVar("Sound_EnableAllSound")
|
||||
self.oldEnableMusic = GetCVar("Sound_EnableMusic")
|
||||
|
||||
SetCVar("Sound_EnableAllSound", 1)
|
||||
SetCVar("Sound_EnableMusic", 1)
|
||||
PlayMusic(E.Media.Sounds.HarlemShake)
|
||||
E:ScheduleTimer("DoTheHarlemShake", 15.5)
|
||||
|
||||
self.massiveShakeObjects = {}
|
||||
tinsert(self.massiveShakeObjects, GameTooltip)
|
||||
tinsert(self.massiveShakeObjects, Minimap)
|
||||
tinsert(self.massiveShakeObjects, WatchFrame)
|
||||
tinsert(self.massiveShakeObjects, LeftChatPanel)
|
||||
tinsert(self.massiveShakeObjects, RightChatPanel)
|
||||
tinsert(self.massiveShakeObjects, LeftChatToggleButton)
|
||||
tinsert(self.massiveShakeObjects, RightChatToggleButton)
|
||||
|
||||
if ElvUI_ReputationBar then
|
||||
tinsert(self.massiveShakeObjects, ElvUI_ReputationBar)
|
||||
end
|
||||
if ElvUI_ExperienceBar then
|
||||
tinsert(self.massiveShakeObjects, ElvUI_ExperienceBar)
|
||||
end
|
||||
|
||||
for unit in pairs(UF.units) do
|
||||
tinsert(self.massiveShakeObjects, UF[unit])
|
||||
end
|
||||
|
||||
for _, header in pairs(UF.headers) do
|
||||
tinsert(self.massiveShakeObjects, header)
|
||||
end
|
||||
|
||||
for _, bar in pairs(AB.handledBars) do
|
||||
for i = 1, #bar.buttons do
|
||||
tinsert(self.massiveShakeObjects, bar.buttons[i])
|
||||
end
|
||||
end
|
||||
|
||||
if ElvUI_StanceBar then
|
||||
for i = 1, #ElvUI_StanceBar.buttons do
|
||||
tinsert(self.massiveShakeObjects, ElvUI_StanceBar.buttons[i])
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, NUM_PET_ACTION_SLOTS do
|
||||
local button = _G["PetActionButton"..i]
|
||||
if button then
|
||||
tinsert(self.massiveShakeObjects, button)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:HarlemShakeToggle()
|
||||
self:StaticPopup_Show("HARLEM_SHAKE")
|
||||
end
|
||||
end
|
||||
|
||||
--Hello Kitty (Activate with command: /hellokitty)
|
||||
--This is one of those pranks where you either love it or hate it I think
|
||||
--Unfortunately there was a bug which caused some of the hello kitty changes to stick,
|
||||
-- when they should have reverted to the original settings. This bug was fixed later on.
|
||||
do
|
||||
local function OnDragStart(self)
|
||||
self:StartMoving()
|
||||
end
|
||||
|
||||
local function OnDragStop(self)
|
||||
self:StopMovingOrSizing()
|
||||
end
|
||||
|
||||
local function OnUpdate(self, elapsed)
|
||||
if self.elapsed and self.elapsed > 0.1 then
|
||||
self.tex:SetTexCoord((self.curFrame - 1) * 0.1, 0, (self.curFrame - 1) * 0.1, 1, self.curFrame * 0.1, 0, self.curFrame * 0.1, 1)
|
||||
|
||||
if self.countUp then
|
||||
self.curFrame = self.curFrame + 1
|
||||
else
|
||||
self.curFrame = self.curFrame - 1
|
||||
end
|
||||
|
||||
if self.curFrame > 10 then
|
||||
self.countUp = false
|
||||
self.curFrame = 9
|
||||
elseif self.curFrame < 1 then
|
||||
self.countUp = true
|
||||
self.curFrame = 2
|
||||
end
|
||||
self.elapsed = 0
|
||||
else
|
||||
self.elapsed = (self.elapsed or 0) + elapsed
|
||||
end
|
||||
end
|
||||
|
||||
function E:SetupHelloKitty()
|
||||
if not self.db.tempSettings then
|
||||
self.db.tempSettings = {}
|
||||
end
|
||||
|
||||
--Store old settings
|
||||
local t = self.db.tempSettings
|
||||
local c = self.db.general.backdropcolor
|
||||
if self:HelloKittyFixCheck() then
|
||||
E:HelloKittyFix()
|
||||
else
|
||||
self.oldEnableAllSound = GetCVar("Sound_EnableAllSound")
|
||||
self.oldEnableMusic = GetCVar("Sound_EnableMusic")
|
||||
|
||||
t.backdropcolor = {r = c.r, g = c.g, b = c.b}
|
||||
c = self.db.general.backdropfadecolor
|
||||
t.backdropfadecolor = {r = c.r, g = c.g, b = c.b, a = c.a}
|
||||
c = self.db.general.bordercolor
|
||||
t.bordercolor = {r = c.r, g = c.g, b = c.b}
|
||||
c = self.db.general.valuecolor
|
||||
t.valuecolor = {r = c.r, g = c.g, b = c.b}
|
||||
|
||||
t.panelBackdropNameLeft = self.db.chat.panelBackdropNameLeft
|
||||
t.panelBackdropNameRight = self.db.chat.panelBackdropNameRight
|
||||
|
||||
c = self.db.unitframe.colors.health
|
||||
t.health = {r = c.r, g = c.g, b = c.b}
|
||||
t.healthclass = self.db.unitframe.colors.healthclass
|
||||
|
||||
c = self.db.unitframe.colors.castColor
|
||||
t.castColor = {r = c.r, g = c.g, b = c.b}
|
||||
t.transparentCastbar = self.db.unitframe.colors.transparentCastbar
|
||||
|
||||
c = self.db.unitframe.colors.auraBarBuff
|
||||
t.auraBarBuff = {r = c.r, g = c.g, b = c.b}
|
||||
t.transparentAurabars = self.db.unitframe.colors.transparentAurabars
|
||||
|
||||
--Apply new settings
|
||||
self.db.general.backdropfadecolor = {r = 131/255, g = 36/255, b = 130/255, a = 0.36}
|
||||
self.db.general.backdropcolor = {r = 223/255, g = 76/255, b = 188/255}
|
||||
self.db.general.bordercolor = {r = 223/255, g = 217/255, b = 47/255}
|
||||
self.db.general.valuecolor = {r = 223/255, g = 217/255, b = 47/255}
|
||||
|
||||
self.db.chat.panelBackdropNameLeft = E.Media.Textures.HelloKittyChat
|
||||
self.db.chat.panelBackdropNameRight = E.Media.Textures.HelloKittyChat
|
||||
|
||||
self.db.unitframe.colors.castColor = {r = 223/255, g = 76/255, b = 188/255}
|
||||
self.db.unitframe.colors.transparentCastbar = true
|
||||
|
||||
self.db.unitframe.colors.auraBarBuff = {r = 223/255, g = 76/255, b = 188/255}
|
||||
self.db.unitframe.colors.transparentAurabars = true
|
||||
|
||||
self.db.unitframe.colors.health = {r = 223/255, g = 76/255, b = 188/255}
|
||||
self.db.unitframe.colors.healthclass = false
|
||||
|
||||
SetCVar("Sound_EnableAllSound", 1)
|
||||
SetCVar("Sound_EnableMusic", 1)
|
||||
PlayMusic(E.Media.Sounds.HelloKitty)
|
||||
E:StaticPopup_Show("HELLO_KITTY_END")
|
||||
|
||||
self.db.general.kittys = true
|
||||
self:CreateKittys()
|
||||
|
||||
self:UpdateAll()
|
||||
end
|
||||
end
|
||||
|
||||
function E:RestoreHelloKitty()
|
||||
--Store old settings
|
||||
self.db.general.kittys = false
|
||||
if HelloKittyLeft then
|
||||
HelloKittyLeft:Hide()
|
||||
HelloKittyRight:Hide()
|
||||
end
|
||||
|
||||
if not self.db.tempSettings then return end
|
||||
if self:HelloKittyFixCheck() then
|
||||
self:HelloKittyFix()
|
||||
self.db.tempSettings = nil
|
||||
return
|
||||
end
|
||||
local c = self.db.tempSettings.backdropcolor
|
||||
self.db.general.backdropcolor = {r = c.r, g = c.g, b = c.b}
|
||||
|
||||
c = self.db.tempSettings.backdropfadecolor
|
||||
self.db.general.backdropfadecolor = {r = c.r, g = c.g, b = c.b, a = (c.a or 0.8)}
|
||||
|
||||
c = self.db.tempSettings.bordercolor
|
||||
self.db.general.bordercolor = {r = c.r, g = c.g, b = c.b}
|
||||
|
||||
c = self.db.tempSettings.valuecolor
|
||||
self.db.general.valuecolor = {r = c.r, g = c.g, b = c.b}
|
||||
|
||||
self.db.chat.panelBackdropNameLeft = self.db.tempSettings.panelBackdropNameLeft
|
||||
self.db.chat.panelBackdropNameRight = self.db.tempSettings.panelBackdropNameRight
|
||||
|
||||
c = self.db.tempSettings.health
|
||||
self.db.unitframe.colors.health = {r = c.r, g = c.g, b = c.b}
|
||||
self.db.unitframe.colors.healthclass = self.db.tempSettings.healthclass
|
||||
|
||||
c = self.db.tempSettings.castColor
|
||||
self.db.unitframe.colors.castColor = {r = c.r, g = c.g, b = c.b}
|
||||
self.db.unitframe.colors.transparentCastbar = self.db.tempSettings.transparentCastbar
|
||||
|
||||
c = self.db.tempSettings.auraBarBuff
|
||||
self.db.unitframe.colors.auraBarBuff = {r = c.r, g = c.g, b = c.b}
|
||||
self.db.unitframe.colors.transparentAurabars = self.db.tempSettings.transparentAurabars
|
||||
|
||||
self.db.tempSettings = nil
|
||||
|
||||
self:UpdateAll()
|
||||
end
|
||||
|
||||
function E:CreateKittys()
|
||||
if HelloKittyLeft then
|
||||
HelloKittyLeft:Show()
|
||||
HelloKittyRight:Show()
|
||||
return
|
||||
end
|
||||
local helloKittyLeft = CreateFrame("Frame", "HelloKittyLeft", UIParent)
|
||||
helloKittyLeft:SetSize(120, 128)
|
||||
helloKittyLeft:SetMovable(true)
|
||||
helloKittyLeft:EnableMouse(true)
|
||||
helloKittyLeft:RegisterForDrag("LeftButton")
|
||||
helloKittyLeft:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMRIGHT", 2, -4)
|
||||
helloKittyLeft.tex = helloKittyLeft:CreateTexture(nil, "OVERLAY")
|
||||
helloKittyLeft.tex:SetAllPoints()
|
||||
helloKittyLeft.tex:SetTexture(E.Media.Textures.HelloKitty)
|
||||
helloKittyLeft.tex:SetTexCoord(0, 0, 0, 1, 0, 0, 0, 1)
|
||||
helloKittyLeft.curFrame = 1
|
||||
helloKittyLeft.countUp = true
|
||||
helloKittyLeft:SetClampedToScreen(true)
|
||||
helloKittyLeft:SetScript("OnDragStart", OnDragStart)
|
||||
helloKittyLeft:SetScript("OnDragStop", OnDragStop)
|
||||
helloKittyLeft:SetScript("OnUpdate", OnUpdate)
|
||||
|
||||
local helloKittyRight = CreateFrame("Frame", "HelloKittyRight", UIParent)
|
||||
helloKittyRight:SetSize(120, 128)
|
||||
helloKittyRight:SetMovable(true)
|
||||
helloKittyRight:EnableMouse(true)
|
||||
helloKittyRight:RegisterForDrag("LeftButton")
|
||||
helloKittyRight:Point("BOTTOMRIGHT", RightChatPanel, "BOTTOMLEFT", -2, -4)
|
||||
helloKittyRight.tex = helloKittyRight:CreateTexture(nil, "OVERLAY")
|
||||
helloKittyRight.tex:SetAllPoints()
|
||||
helloKittyRight.tex:SetTexture(E.Media.Textures.HelloKitty)
|
||||
helloKittyRight.tex:SetTexCoord(0, 0, 0, 1, 0, 0, 0, 1)
|
||||
helloKittyRight.curFrame = 10
|
||||
helloKittyRight.countUp = false
|
||||
helloKittyRight:SetClampedToScreen(true)
|
||||
helloKittyRight:SetScript("OnDragStart", OnDragStart)
|
||||
helloKittyRight:SetScript("OnDragStop", OnDragStop)
|
||||
helloKittyRight:SetScript("OnUpdate", OnUpdate)
|
||||
end
|
||||
|
||||
--When it bugged out for a user the command "/hellokittyfix" attempted to restore the changed settings to default
|
||||
function E:HelloKittyFixCheck(secondCheck)
|
||||
local t = self.db.tempSettings
|
||||
if not t and not secondCheck then t = self.db.general end
|
||||
if t and t.backdropcolor then
|
||||
return self:Round(t.backdropcolor.r, 2) == 0.87 and self:Round(t.backdropcolor.g, 2) == 0.3 and self:Round(t.backdropcolor.b, 2) == 0.74
|
||||
end
|
||||
end
|
||||
|
||||
function E:HelloKittyFix()
|
||||
local c = P.general.backdropcolor
|
||||
self.db.general.backdropcolor = {r = c.r, g = c.g, b = c.b}
|
||||
|
||||
c = P.general.backdropfadecolor
|
||||
self.db.general.backdropfadecolor = {r = c.r, g = c.g, b = c.b, a = (c.a or 0.8)}
|
||||
|
||||
c = P.general.bordercolor
|
||||
self.db.general.bordercolor = {r = c.r, g = c.g, b = c.b}
|
||||
|
||||
c = P.general.valuecolor
|
||||
self.db.general.valuecolor = {r = c.r, g = c.g, b = c.b}
|
||||
|
||||
self.db.chat.panelBackdropNameLeft = ""
|
||||
self.db.chat.panelBackdropNameRight = ""
|
||||
|
||||
c = P.unitframe.colors.health
|
||||
self.db.unitframe.colors.health = {r = c.r, g = c.g, b = c.b}
|
||||
|
||||
c = P.unitframe.colors.castColor
|
||||
self.db.unitframe.colors.castColor = {r = c.r, g = c.g, b = c.b}
|
||||
self.db.unitframe.colors.transparentCastbar = false
|
||||
|
||||
c = P.unitframe.colors.castColor
|
||||
self.db.unitframe.colors.auraBarBuff = {r = c.r, g = c.g, b = c.b}
|
||||
self.db.unitframe.colors.transparentAurabars = false
|
||||
|
||||
if HelloKittyLeft then
|
||||
HelloKittyLeft:Hide()
|
||||
HelloKittyRight:Hide()
|
||||
self.db.general.kittys = nil
|
||||
return
|
||||
end
|
||||
|
||||
self.db.tempSettings = nil
|
||||
self:UpdateAll()
|
||||
end
|
||||
|
||||
function E:HelloKittyToggle()
|
||||
if HelloKittyLeft and HelloKittyLeft:IsShown() then
|
||||
self:RestoreHelloKitty()
|
||||
else
|
||||
self:StaticPopup_Show("HELLO_KITTY")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,280 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)) --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local DT = E:GetModule("DataTexts")
|
||||
local AB = E:GetModule("ActionBars")
|
||||
|
||||
--Lua functions
|
||||
local tonumber, type = tonumber, type
|
||||
local format, lower, match, split = string.format, string.lower, string.match, string.split
|
||||
--WoW API / Variables
|
||||
local InCombatLockdown = InCombatLockdown
|
||||
local UIFrameFadeOut, UIFrameFadeIn = UIFrameFadeOut, UIFrameFadeIn
|
||||
local EnableAddOn, DisableAllAddOns = EnableAddOn, DisableAllAddOns
|
||||
local SetCVar = SetCVar
|
||||
local ReloadUI = ReloadUI
|
||||
local debugprofilestop = debugprofilestop
|
||||
local UpdateAddOnCPUUsage, GetAddOnCPUUsage = UpdateAddOnCPUUsage, GetAddOnCPUUsage
|
||||
local ResetCPUUsage = ResetCPUUsage
|
||||
local GetAddOnInfo = GetAddOnInfo
|
||||
local GetCVarBool = GetCVarBool
|
||||
local ERR_NOT_IN_COMBAT = ERR_NOT_IN_COMBAT
|
||||
|
||||
function E:Grid(msg)
|
||||
msg = msg and tonumber(msg)
|
||||
if type(msg) == "number" and (msg <= 256 and msg >= 4) then
|
||||
E.db.gridSize = msg
|
||||
E:Grid_Show()
|
||||
elseif ElvUIGrid and ElvUIGrid:IsShown() then
|
||||
E:Grid_Hide()
|
||||
else
|
||||
E:Grid_Show()
|
||||
end
|
||||
end
|
||||
|
||||
function E:LuaError(msg)
|
||||
msg = lower(msg)
|
||||
if msg == "on" then
|
||||
DisableAllAddOns()
|
||||
EnableAddOn("ElvUI")
|
||||
EnableAddOn("ElvUI_OptionsUI")
|
||||
SetCVar("scriptErrors", 1)
|
||||
ReloadUI()
|
||||
elseif msg == "off" then
|
||||
SetCVar("scriptErrors", 0)
|
||||
E:Print("Lua errors off.")
|
||||
else
|
||||
E:Print("/luaerror on - /luaerror off")
|
||||
end
|
||||
end
|
||||
|
||||
function E:BGStats()
|
||||
DT.ForceHideBGStats = nil
|
||||
DT:LoadDataTexts()
|
||||
|
||||
E:Print(L["Battleground datatexts will now show again if you are inside a battleground."])
|
||||
end
|
||||
|
||||
local function OnCallback(command)
|
||||
MacroEditBox:GetScript("OnEvent")(MacroEditBox, "EXECUTE_CHAT_LINE", command)
|
||||
end
|
||||
|
||||
function E:DelayScriptCall(msg)
|
||||
local secs, command = match(msg, "^(%S+)%s+(.*)$")
|
||||
secs = tonumber(secs)
|
||||
if (not secs) or (#command == 0) then
|
||||
self:Print("usage: /in <seconds> <command>")
|
||||
self:Print("example: /in 1.5 /say hi")
|
||||
else
|
||||
E:Delay(secs, OnCallback, command)
|
||||
end
|
||||
end
|
||||
|
||||
function FarmMode()
|
||||
if InCombatLockdown() then E:Print(ERR_NOT_IN_COMBAT) return end
|
||||
if not E.private.general.minimap.enable then return end
|
||||
|
||||
if Minimap:IsShown() then
|
||||
UIFrameFadeOut(Minimap, 0.3)
|
||||
UIFrameFadeIn(FarmModeMap, 0.3)
|
||||
Minimap.fadeInfo.finishedFunc = function()
|
||||
Minimap:Hide()
|
||||
FarmModeMap:SetAlpha(1)
|
||||
|
||||
local zoomLevel = Minimap:GetZoom()
|
||||
if zoomLevel < 5 then
|
||||
Minimap:SetZoom(zoomLevel + 1)
|
||||
Minimap:SetZoom(zoomLevel)
|
||||
else
|
||||
Minimap:SetZoom(zoomLevel - 1)
|
||||
Minimap:SetZoom(zoomLevel)
|
||||
end
|
||||
end
|
||||
FarmModeMap.enabled = true
|
||||
else
|
||||
UIFrameFadeOut(FarmModeMap, 0.3)
|
||||
UIFrameFadeIn(Minimap, 0.3)
|
||||
FarmModeMap.fadeInfo.finishedFunc = function()
|
||||
FarmModeMap:Hide()
|
||||
Minimap:SetAlpha(1)
|
||||
|
||||
local zoomLevel = Minimap:GetZoom()
|
||||
if zoomLevel < 5 then
|
||||
Minimap:SetZoom(zoomLevel + 1)
|
||||
Minimap:SetZoom(zoomLevel)
|
||||
else
|
||||
Minimap:SetZoom(zoomLevel - 1)
|
||||
Minimap:SetZoom(zoomLevel)
|
||||
end
|
||||
end
|
||||
FarmModeMap.enabled = false
|
||||
end
|
||||
end
|
||||
|
||||
function E:FarmMode(msg)
|
||||
if not E.private.general.minimap.enable then return end
|
||||
|
||||
if msg and type(tonumber(msg)) == "number" and tonumber(msg) <= 500 and tonumber(msg) >= 20 and not InCombatLockdown() then
|
||||
E.db.farmSize = tonumber(msg)
|
||||
FarmModeMap:Size(tonumber(msg))
|
||||
end
|
||||
|
||||
FarmMode()
|
||||
end
|
||||
|
||||
-- make this a locale later?
|
||||
local MassKickMessage = "Guild Cleanup Results: Removed all guild members below rank %s, that have a minimal level of %s, and have not been online for at least: %s days."
|
||||
function E:MassGuildKick(msg)
|
||||
local minLevel, minDays, minRankIndex = split(",", msg)
|
||||
minRankIndex = tonumber(minRankIndex)
|
||||
minLevel = tonumber(minLevel)
|
||||
minDays = tonumber(minDays)
|
||||
|
||||
if not minLevel or not minDays then
|
||||
E:Print("Usage: /cleanguild <minLevel>, <minDays>, [<minRankIndex>]")
|
||||
return
|
||||
end
|
||||
|
||||
if minDays > 31 then
|
||||
E:Print("Maximum days value must be below 32.")
|
||||
return
|
||||
end
|
||||
|
||||
if not minRankIndex then minRankIndex = GuildControlGetNumRanks() - 1 end
|
||||
|
||||
for i = 1, GetNumGuildMembers() do
|
||||
local name, _, rankIndex, level, _, _, note, officerNote, connected, _, classFileName = GetGuildRosterInfo(i)
|
||||
local minLevelx = minLevel
|
||||
|
||||
if classFileName == "DEATHKNIGHT" then
|
||||
minLevelx = minLevelx + 55
|
||||
end
|
||||
|
||||
if not connected then
|
||||
local years, months, days = GetGuildRosterLastOnline(i)
|
||||
if days ~= nil and ((years > 0 or months > 0 or days >= minDays) and rankIndex >= minRankIndex)
|
||||
and note ~= nil and officerNote ~= nil and (level <= minLevelx) then
|
||||
GuildUninvite(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
SendChatMessage(format(MassKickMessage, GuildControlGetRankName(minRankIndex), minLevel, minDays), "GUILD")
|
||||
end
|
||||
|
||||
local num_frames = 0
|
||||
local function OnUpdate()
|
||||
num_frames = num_frames + 1
|
||||
end
|
||||
local f = CreateFrame("Frame")
|
||||
f:Hide()
|
||||
f:SetScript("OnUpdate", OnUpdate)
|
||||
|
||||
local toggleMode, debugTimer, cpuImpactMessage = false, 0, "Consumed %sms per frame. Each frame took %sms to render."
|
||||
function E:GetCPUImpact()
|
||||
if not GetCVarBool("scriptProfile") then
|
||||
E:Print("For `/cpuimpact` to work, you need to enable script profiling via: `/console scriptProfile 1` then reload. Disable after testing by setting it back to 0.")
|
||||
return
|
||||
end
|
||||
|
||||
if not toggleMode then
|
||||
ResetCPUUsage()
|
||||
toggleMode, num_frames, debugTimer = true, 0, debugprofilestop()
|
||||
self:Print("CPU Impact being calculated, type /cpuimpact to get results when you are ready.")
|
||||
f:Show()
|
||||
else
|
||||
f:Hide()
|
||||
local ms_passed = debugprofilestop() - debugTimer
|
||||
UpdateAddOnCPUUsage()
|
||||
|
||||
local per, passed =
|
||||
((num_frames == 0 and 0) or (GetAddOnCPUUsage("ElvUI") / num_frames)),
|
||||
((num_frames == 0 and 0) or (ms_passed / num_frames))
|
||||
self:Print(format(cpuImpactMessage, per and per > 0 and format("%.3f", per) or 0, passed and passed > 0 and format("%.3f", passed) or 0))
|
||||
toggleMode = false
|
||||
end
|
||||
end
|
||||
|
||||
local BLIZZARD_ADDONS = {
|
||||
"Blizzard_AchievementUI",
|
||||
"Blizzard_ArenaUI",
|
||||
"Blizzard_AuctionUI",
|
||||
"Blizzard_BarbershopUI",
|
||||
"Blizzard_BattlefieldMinimap",
|
||||
"Blizzard_BindingUI",
|
||||
"Blizzard_Calendar",
|
||||
"Blizzard_CombatLog",
|
||||
"Blizzard_CombatText",
|
||||
"Blizzard_DebugTools",
|
||||
"Blizzard_GlyphUI",
|
||||
"Blizzard_GMChatUI",
|
||||
"Blizzard_GMSurveyUI",
|
||||
"Blizzard_GuildBankUI",
|
||||
"Blizzard_InspectUI",
|
||||
"Blizzard_ItemSocketingUI",
|
||||
"Blizzard_MacroUI",
|
||||
"Blizzard_RaidUI",
|
||||
"Blizzard_TalentUI",
|
||||
"Blizzard_TimeManager",
|
||||
"Blizzard_TokenUI",
|
||||
"Blizzard_TradeSkillUI",
|
||||
"Blizzard_TrainerUI"
|
||||
}
|
||||
|
||||
function E:EnableBlizzardAddOns()
|
||||
for _, addon in pairs(BLIZZARD_ADDONS) do
|
||||
local reason = select(5, GetAddOnInfo(addon))
|
||||
if reason == "DISABLED" then
|
||||
EnableAddOn(addon)
|
||||
E:Print("The following addon was re-enabled:", addon)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:ChangeRole(role)
|
||||
local roles = {
|
||||
["melee"]="Melee",
|
||||
["caster"]="Caster",
|
||||
["ranged"]="Ranged",
|
||||
["tank"]="Tank",
|
||||
}
|
||||
E.Role = roles[lower(role)] or "Melee"
|
||||
print("Role was changed to:", E.Role)
|
||||
end
|
||||
|
||||
function E:LoadCommands()
|
||||
self:RegisterChatCommand("in", "DelayScriptCall")
|
||||
self:RegisterChatCommand("ec", "ToggleOptionsUI")
|
||||
self:RegisterChatCommand("elvui", "ToggleOptionsUI")
|
||||
self:RegisterChatCommand("cpuimpact", "GetCPUImpact")
|
||||
|
||||
self:RegisterChatCommand("cpuusage", "GetTopCPUFunc")
|
||||
-- args: module, showall, delay, minCalls
|
||||
-- Example1: /cpuusage all
|
||||
-- Example2: /cpuusage Bags true
|
||||
-- Example3: /cpuusage UnitFrames nil 50 25
|
||||
-- Note: showall, delay, and minCalls will default if not set
|
||||
-- arg1 can be "all" this will scan all registered modules!
|
||||
|
||||
self:RegisterChatCommand("bgstats", "BGStats")
|
||||
self:RegisterChatCommand("hellokitty", "HelloKittyToggle")
|
||||
self:RegisterChatCommand("hellokittyfix", "HelloKittyFix")
|
||||
self:RegisterChatCommand("harlemshake", "HarlemShakeToggle")
|
||||
self:RegisterChatCommand("luaerror", "LuaError")
|
||||
self:RegisterChatCommand("egrid", "Grid")
|
||||
self:RegisterChatCommand("moveui", "ToggleMoveMode")
|
||||
self:RegisterChatCommand("resetui", "ResetUI")
|
||||
self:RegisterChatCommand("enable", "EnableAddon")
|
||||
self:RegisterChatCommand("disable", "DisableAddon")
|
||||
self:RegisterChatCommand("farmmode", "FarmMode")
|
||||
self:RegisterChatCommand("cleanguild", "MassGuildKick")
|
||||
self:RegisterChatCommand("estatus", "ShowStatusReport")
|
||||
|
||||
self:RegisterChatCommand("role", "ChangeRole")
|
||||
-- This command is added for Ascension. Role checks will be unreliable, but
|
||||
-- this will allow one to set Role manually.
|
||||
-- /role expects one of "melee", "caster", "ranged", "tank"
|
||||
-- and defaults to "melee" if no role is provided.
|
||||
|
||||
if E.private.actionbar.enable then
|
||||
self:RegisterChatCommand("kb", AB.ActivateBindMode)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,509 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); -- Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local S = E:GetModule("Skins")
|
||||
|
||||
--Lua functions
|
||||
local _G = _G
|
||||
local unpack = unpack
|
||||
local type, ipairs, tonumber = type, ipairs, tonumber
|
||||
local floor, select = floor, select
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local IsAddOnLoaded = IsAddOnLoaded
|
||||
local InCombatLockdown = InCombatLockdown
|
||||
local EditBox_ClearFocus = EditBox_ClearFocus
|
||||
local RESET = RESET
|
||||
|
||||
local selectedValue, grid = "ALL"
|
||||
|
||||
E.ConfigModeLayouts = {
|
||||
"ALL",
|
||||
"GENERAL",
|
||||
"SOLO",
|
||||
"PARTY",
|
||||
"ARENA",
|
||||
"RAID",
|
||||
"ACTIONBARS"
|
||||
}
|
||||
|
||||
E.ConfigModeLocalizedStrings = {
|
||||
ALL = ALL,
|
||||
GENERAL = GENERAL,
|
||||
SOLO = SOLO,
|
||||
PARTY = PARTY,
|
||||
ARENA = ARENA,
|
||||
RAID = RAID,
|
||||
ACTIONBARS = ACTIONBARS_LABEL
|
||||
}
|
||||
|
||||
function E:Grid_Show()
|
||||
if not grid then
|
||||
E:Grid_Create()
|
||||
elseif grid.boxSize ~= E.db.gridSize then
|
||||
grid:Hide()
|
||||
E:Grid_Create()
|
||||
else
|
||||
grid:Show()
|
||||
end
|
||||
end
|
||||
|
||||
function E:Grid_Hide()
|
||||
if grid then
|
||||
grid:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
function E:ToggleMoveMode(override, configType)
|
||||
if InCombatLockdown() then return end
|
||||
if override ~= nil and override ~= "" then E.ConfigurationMode = override end
|
||||
|
||||
if E.ConfigurationMode ~= true then
|
||||
E:Grid_Show()
|
||||
|
||||
if not ElvUIMoverPopupWindow then
|
||||
E:CreateMoverPopup()
|
||||
end
|
||||
|
||||
ElvUIMoverPopupWindow:Show()
|
||||
|
||||
if IsAddOnLoaded("ElvUI_OptionsUI") then
|
||||
if E.Libs.AceConfigDialog then
|
||||
E.Libs.AceConfigDialog:Close("ElvUI")
|
||||
end
|
||||
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
E.ConfigurationMode = true
|
||||
else
|
||||
E:Grid_Hide()
|
||||
|
||||
if ElvUIMoverPopupWindow then
|
||||
ElvUIMoverPopupWindow:Hide()
|
||||
end
|
||||
|
||||
E.ConfigurationMode = false
|
||||
end
|
||||
|
||||
if type(configType) ~= "string" then
|
||||
configType = nil
|
||||
end
|
||||
|
||||
self:ToggleMovers(E.ConfigurationMode, configType or "ALL")
|
||||
end
|
||||
|
||||
function E:Grid_GetRegion()
|
||||
if grid then
|
||||
if grid.regionCount and grid.regionCount > 0 then
|
||||
local line = select(grid.regionCount, grid:GetRegions())
|
||||
grid.regionCount = grid.regionCount - 1
|
||||
line:SetAlpha(1)
|
||||
return line
|
||||
else
|
||||
return grid:CreateTexture()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:Grid_Create()
|
||||
if not grid then
|
||||
grid = CreateFrame("Frame", "ElvUIGrid", E.UIParent)
|
||||
grid:SetFrameStrata("BACKGROUND")
|
||||
else
|
||||
grid.regionCount = 0
|
||||
local numRegions = grid:GetNumRegions()
|
||||
for i = 1, numRegions do
|
||||
local region = select(i, grid:GetRegions())
|
||||
if region and region.IsObjectType and region:IsObjectType("Texture") then
|
||||
grid.regionCount = grid.regionCount + 1
|
||||
region:SetAlpha(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local size = E.mult
|
||||
local width, height = E.UIParent:GetSize()
|
||||
|
||||
local ratio = width / height
|
||||
local hStepheight = height * ratio
|
||||
local wStep = width / E.db.gridSize
|
||||
local hStep = hStepheight / E.db.gridSize
|
||||
|
||||
grid.boxSize = E.db.gridSize
|
||||
grid:SetPoint("CENTER", E.UIParent)
|
||||
grid:SetSize(width, height)
|
||||
grid:Show()
|
||||
|
||||
for i = 0, E.db.gridSize do
|
||||
local tx = E:Grid_GetRegion()
|
||||
if i == E.db.gridSize / 2 then
|
||||
tx:SetTexture(1, 0, 0)
|
||||
tx:SetDrawLayer("BORDER")
|
||||
else
|
||||
tx:SetTexture(0, 0, 0)
|
||||
tx:SetDrawLayer("BACKGROUND")
|
||||
end
|
||||
tx:ClearAllPoints()
|
||||
tx:Point("TOPLEFT", grid, "TOPLEFT", i*wStep - (size/2), 0)
|
||||
tx:Point("BOTTOMRIGHT", grid, "BOTTOMLEFT", i*wStep + (size/2), 0)
|
||||
end
|
||||
|
||||
do
|
||||
local tx = E:Grid_GetRegion()
|
||||
tx:SetTexture(1, 0, 0)
|
||||
tx:SetDrawLayer("BORDER")
|
||||
tx:ClearAllPoints()
|
||||
tx:Point("TOPLEFT", grid, "TOPLEFT", 0, -(height/2) + (size/2))
|
||||
tx:Point("BOTTOMRIGHT", grid, "TOPRIGHT", 0, -(height/2 + size/2))
|
||||
end
|
||||
|
||||
for i = 1, floor((height/2)/hStep) do
|
||||
local tx = E:Grid_GetRegion()
|
||||
tx:SetTexture(0, 0, 0)
|
||||
tx:SetDrawLayer("BACKGROUND")
|
||||
tx:ClearAllPoints()
|
||||
tx:Point("TOPLEFT", grid, "TOPLEFT", 0, -(height/2+i*hStep) + (size/2))
|
||||
tx:Point("BOTTOMRIGHT", grid, "TOPRIGHT", 0, -(height/2+i*hStep + size/2))
|
||||
|
||||
tx = E:Grid_GetRegion()
|
||||
tx:SetTexture(0, 0, 0)
|
||||
tx:SetDrawLayer("BACKGROUND")
|
||||
tx:ClearAllPoints()
|
||||
tx:Point("TOPLEFT", grid, "TOPLEFT", 0, -(height/2-i*hStep) + (size/2))
|
||||
tx:Point("BOTTOMRIGHT", grid, "TOPRIGHT", 0, -(height/2-i*hStep + size/2))
|
||||
end
|
||||
end
|
||||
|
||||
local function ConfigMode_OnClick(self)
|
||||
selectedValue = self.value
|
||||
E:ToggleMoveMode(false, self.value)
|
||||
UIDropDownMenu_SetSelectedValue(ElvUIMoverPopupWindowDropDown, self.value)
|
||||
end
|
||||
|
||||
local function ConfigMode_Initialize()
|
||||
local info = _G.UIDropDownMenu_CreateInfo()
|
||||
info.func = ConfigMode_OnClick
|
||||
|
||||
for _, configMode in ipairs(E.ConfigModeLayouts) do
|
||||
info.text = E.ConfigModeLocalizedStrings[configMode]
|
||||
info.value = configMode
|
||||
UIDropDownMenu_AddButton(info)
|
||||
end
|
||||
|
||||
UIDropDownMenu_SetSelectedValue(ElvUIMoverPopupWindowDropDown, selectedValue)
|
||||
end
|
||||
|
||||
function E:NudgeMover(nudgeX, nudgeY)
|
||||
local mover = ElvUIMoverNudgeWindow.child
|
||||
local x, y, point = E:CalculateMoverPoints(mover, nudgeX, nudgeY)
|
||||
|
||||
mover:ClearAllPoints()
|
||||
mover:Point(mover.positionOverride or point, E.UIParent, mover.positionOverride and "BOTTOMLEFT" or point, x, y)
|
||||
E:SaveMoverPosition(mover.name)
|
||||
|
||||
--Update coordinates in Nudge Window
|
||||
E:UpdateNudgeFrame(mover, x, y)
|
||||
end
|
||||
|
||||
function E:UpdateNudgeFrame(mover, x, y)
|
||||
if not (x and y) then
|
||||
x, y = E:CalculateMoverPoints(mover)
|
||||
end
|
||||
|
||||
x = E:Round(x, 0)
|
||||
y = E:Round(y, 0)
|
||||
|
||||
local ElvUIMoverNudgeWindow = ElvUIMoverNudgeWindow
|
||||
ElvUIMoverNudgeWindow.xOffset:SetText(x)
|
||||
ElvUIMoverNudgeWindow.yOffset:SetText(y)
|
||||
ElvUIMoverNudgeWindow.xOffset.currentValue = x
|
||||
ElvUIMoverNudgeWindow.yOffset.currentValue = y
|
||||
ElvUIMoverNudgeWindow.title:SetText(mover.textString)
|
||||
end
|
||||
|
||||
function E:AssignFrameToNudge()
|
||||
ElvUIMoverNudgeWindow.child = self
|
||||
E:UpdateNudgeFrame(self)
|
||||
end
|
||||
|
||||
function E:CreateMoverPopup()
|
||||
local f = CreateFrame("Frame", "ElvUIMoverPopupWindow", UIParent)
|
||||
f:SetFrameStrata("DIALOG")
|
||||
f:SetToplevel(true)
|
||||
f:EnableMouse(true)
|
||||
f:SetMovable(true)
|
||||
f:SetFrameLevel(99)
|
||||
f:SetClampedToScreen(true)
|
||||
f:Width(360)
|
||||
f:Height(195)
|
||||
f:SetTemplate("Transparent")
|
||||
f:Point("BOTTOM", UIParent, "CENTER", 0, 100)
|
||||
f:SetScript("OnHide", function()
|
||||
if ElvUIMoverPopupWindowDropDown then
|
||||
UIDropDownMenu_SetSelectedValue(ElvUIMoverPopupWindowDropDown, "ALL")
|
||||
end
|
||||
end)
|
||||
f:SetBackdropBorderColor(unpack(E.media.rgbvaluecolor))
|
||||
f:CreateShadow(5)
|
||||
f:Hide()
|
||||
|
||||
local header = CreateFrame("Button", nil, f)
|
||||
header:SetTemplate(nil, true)
|
||||
header:Width(100)
|
||||
header:Height(25)
|
||||
header:Point("CENTER", f, "TOP")
|
||||
header:SetFrameLevel(header:GetFrameLevel() + 2)
|
||||
header:EnableMouse(true)
|
||||
header:RegisterForClicks("AnyUp", "AnyDown")
|
||||
header:SetScript("OnMouseDown", function() f:StartMoving() end)
|
||||
header:SetScript("OnMouseUp", function() f:StopMovingOrSizing() end)
|
||||
header:SetBackdropBorderColor(unpack(E.media.rgbvaluecolor))
|
||||
|
||||
local title = header:CreateFontString("OVERLAY")
|
||||
title:FontTemplate()
|
||||
title:Point("CENTER", header, "CENTER")
|
||||
title:SetText("ElvUI")
|
||||
|
||||
local desc = f:CreateFontString("ARTWORK")
|
||||
desc:SetFontObject("GameFontHighlight")
|
||||
desc:SetJustifyV("TOP")
|
||||
desc:SetJustifyH("LEFT")
|
||||
desc:Point("TOPLEFT", 18, -32)
|
||||
desc:Point("BOTTOMRIGHT", -18, 48)
|
||||
desc:SetText(L["DESC_MOVERCONFIG"])
|
||||
|
||||
local snapping = CreateFrame("CheckButton", f:GetName().."CheckButton", f, "OptionsCheckButtonTemplate")
|
||||
_G[snapping:GetName().."Text"]:SetText(L["Sticky Frames"])
|
||||
|
||||
snapping:SetScript("OnShow", function(cb)
|
||||
cb:SetChecked(E.db.general.stickyFrames)
|
||||
end)
|
||||
|
||||
snapping:SetScript("OnClick", function(cb)
|
||||
E.db.general.stickyFrames = cb:GetChecked()
|
||||
end)
|
||||
|
||||
local lock = CreateFrame("Button", f:GetName().."CloseButton", f, "OptionsButtonTemplate")
|
||||
_G[lock:GetName().."Text"]:SetText(L["Lock"])
|
||||
|
||||
lock:SetScript("OnClick", function()
|
||||
E:ToggleMoveMode(true)
|
||||
|
||||
if IsAddOnLoaded("ElvUI_OptionsUI") and E.Libs.AceConfigDialog then
|
||||
E.Libs.AceConfigDialog:Open("ElvUI")
|
||||
end
|
||||
|
||||
selectedValue = "ALL"
|
||||
UIDropDownMenu_SetSelectedValue(ElvUIMoverPopupWindowDropDown, selectedValue)
|
||||
end)
|
||||
|
||||
local align = CreateFrame("EditBox", f:GetName().."EditBox", f, "InputBoxTemplate")
|
||||
align:Width(24)
|
||||
align:Height(17)
|
||||
align:SetAutoFocus(false)
|
||||
align:SetScript("OnEscapePressed", function(eb)
|
||||
eb:SetText(E.db.gridSize)
|
||||
EditBox_ClearFocus(eb)
|
||||
end)
|
||||
align:SetScript("OnEnterPressed", function(eb)
|
||||
local text = eb:GetText()
|
||||
if tonumber(text) then
|
||||
if tonumber(text) <= 256 and tonumber(text) >= 4 then
|
||||
E.db.gridSize = tonumber(text)
|
||||
else
|
||||
eb:SetText(E.db.gridSize)
|
||||
end
|
||||
else
|
||||
eb:SetText(E.db.gridSize)
|
||||
end
|
||||
E:Grid_Show()
|
||||
EditBox_ClearFocus(eb)
|
||||
end)
|
||||
align:SetScript("OnEditFocusLost", function(eb)
|
||||
eb:SetText(E.db.gridSize)
|
||||
end)
|
||||
align:SetScript("OnEditFocusGained", align.HighlightText)
|
||||
align:SetScript("OnShow", function(eb)
|
||||
EditBox_ClearFocus(eb)
|
||||
eb:SetText(E.db.gridSize)
|
||||
end)
|
||||
|
||||
align.text = align:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
align.text:Point("RIGHT", align, "LEFT", -4, 0)
|
||||
align.text:SetText(L["Grid Size:"])
|
||||
|
||||
--position buttons
|
||||
snapping:Point("BOTTOMLEFT", 14, 10)
|
||||
lock:Point("BOTTOMRIGHT", -14, 14)
|
||||
align:Point("TOPRIGHT", lock, "TOPLEFT", -4, -2)
|
||||
|
||||
S:HandleCheckBox(snapping)
|
||||
S:HandleButton(lock)
|
||||
S:HandleEditBox(align)
|
||||
|
||||
f:RegisterEvent("PLAYER_REGEN_DISABLED")
|
||||
f:SetScript("OnEvent", function(mover)
|
||||
if mover:IsShown() then
|
||||
mover:Hide()
|
||||
E:Grid_Hide()
|
||||
E:ToggleMoveMode(true)
|
||||
end
|
||||
end)
|
||||
|
||||
local configMode = CreateFrame("Frame", f:GetName().."DropDown", f, "UIDropDownMenuTemplate")
|
||||
configMode:Point("BOTTOMRIGHT", lock, "TOPRIGHT", 8, -5)
|
||||
S:HandleDropDownBox(configMode, 148)
|
||||
configMode.text = configMode:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
configMode.text:Point("RIGHT", configMode.backdrop, "LEFT", -2, 0)
|
||||
configMode.text:SetText(L["Config Mode:"])
|
||||
|
||||
UIDropDownMenu_Initialize(configMode, ConfigMode_Initialize)
|
||||
|
||||
local nudgeFrame = CreateFrame("Frame", "ElvUIMoverNudgeWindow", E.UIParent)
|
||||
nudgeFrame:SetFrameStrata("DIALOG")
|
||||
nudgeFrame:Width(200)
|
||||
nudgeFrame:Height(110)
|
||||
nudgeFrame:SetTemplate("Transparent")
|
||||
nudgeFrame:CreateShadow(5)
|
||||
nudgeFrame:SetBackdropBorderColor(unpack(E.media.rgbvaluecolor))
|
||||
nudgeFrame:SetFrameLevel(100)
|
||||
nudgeFrame:Hide()
|
||||
nudgeFrame:EnableMouse(true)
|
||||
nudgeFrame:SetClampedToScreen(true)
|
||||
|
||||
ElvUIMoverPopupWindow:HookScript("OnHide", function() ElvUIMoverNudgeWindow:Hide() end)
|
||||
|
||||
desc = nudgeFrame:CreateFontString("ARTWORK")
|
||||
desc:SetFontObject("GameFontHighlight")
|
||||
desc:SetJustifyV("TOP")
|
||||
desc:SetJustifyH("LEFT")
|
||||
desc:Point("TOPLEFT", 18, -15)
|
||||
desc:Point("BOTTOMRIGHT", -18, 28)
|
||||
desc:SetJustifyH("CENTER")
|
||||
nudgeFrame.title = desc
|
||||
|
||||
header = CreateFrame("Button", nil, nudgeFrame)
|
||||
header:SetTemplate(nil, true)
|
||||
header:Width(100)
|
||||
header:Height(25)
|
||||
header:Point("CENTER", nudgeFrame, "TOP")
|
||||
header:SetFrameLevel(header:GetFrameLevel() + 2)
|
||||
header:SetBackdropBorderColor(unpack(E.media.rgbvaluecolor))
|
||||
|
||||
title = header:CreateFontString("OVERLAY")
|
||||
title:FontTemplate()
|
||||
title:Point("CENTER", header, "CENTER")
|
||||
title:SetText(L["Nudge"])
|
||||
|
||||
local xOffset = CreateFrame("EditBox", nudgeFrame:GetName().."XEditBox", nudgeFrame, "InputBoxTemplate")
|
||||
xOffset:Width(50)
|
||||
xOffset:Height(17)
|
||||
xOffset:SetAutoFocus(false)
|
||||
xOffset.currentValue = 0
|
||||
xOffset:SetScript("OnEscapePressed", function(eb)
|
||||
eb:SetText(E:Round(xOffset.currentValue))
|
||||
EditBox_ClearFocus(eb)
|
||||
end)
|
||||
xOffset:SetScript("OnEnterPressed", function(eb)
|
||||
local num = eb:GetText()
|
||||
if tonumber(num) then
|
||||
local diff = num - xOffset.currentValue
|
||||
xOffset.currentValue = num
|
||||
E:NudgeMover(diff)
|
||||
end
|
||||
eb:SetText(E:Round(xOffset.currentValue))
|
||||
EditBox_ClearFocus(eb)
|
||||
end)
|
||||
xOffset:SetScript("OnEditFocusLost", function(eb)
|
||||
eb:SetText(E:Round(xOffset.currentValue))
|
||||
end)
|
||||
xOffset:SetScript("OnEditFocusGained", xOffset.HighlightText)
|
||||
xOffset:SetScript("OnShow", function(eb)
|
||||
EditBox_ClearFocus(eb)
|
||||
eb:SetText(E:Round(xOffset.currentValue))
|
||||
end)
|
||||
|
||||
xOffset.text = xOffset:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
xOffset.text:Point("RIGHT", xOffset, "LEFT", -4, 0)
|
||||
xOffset.text:SetText("X:")
|
||||
xOffset:Point("BOTTOMRIGHT", nudgeFrame, "CENTER", -6, 8)
|
||||
nudgeFrame.xOffset = xOffset
|
||||
S:HandleEditBox(xOffset)
|
||||
|
||||
local yOffset = CreateFrame("EditBox", nudgeFrame:GetName().."YEditBox", nudgeFrame, "InputBoxTemplate")
|
||||
yOffset:Width(50)
|
||||
yOffset:Height(17)
|
||||
yOffset:SetAutoFocus(false)
|
||||
yOffset.currentValue = 0
|
||||
yOffset:SetScript("OnEscapePressed", function(eb)
|
||||
eb:SetText(E:Round(yOffset.currentValue))
|
||||
EditBox_ClearFocus(eb)
|
||||
end)
|
||||
yOffset:SetScript("OnEnterPressed", function(eb)
|
||||
local num = eb:GetText()
|
||||
if tonumber(num) then
|
||||
local diff = num - yOffset.currentValue
|
||||
yOffset.currentValue = num
|
||||
E:NudgeMover(nil, diff)
|
||||
end
|
||||
eb:SetText(E:Round(yOffset.currentValue))
|
||||
EditBox_ClearFocus(eb)
|
||||
end)
|
||||
yOffset:SetScript("OnEditFocusLost", function(eb)
|
||||
eb:SetText(E:Round(yOffset.currentValue))
|
||||
end)
|
||||
yOffset:SetScript("OnEditFocusGained", yOffset.HighlightText)
|
||||
yOffset:SetScript("OnShow", function(eb)
|
||||
EditBox_ClearFocus(eb)
|
||||
eb:SetText(E:Round(yOffset.currentValue))
|
||||
end)
|
||||
|
||||
yOffset.text = yOffset:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
yOffset.text:Point("RIGHT", yOffset, "LEFT", -4, 0)
|
||||
yOffset.text:SetText("Y:")
|
||||
yOffset:Point("BOTTOMLEFT", nudgeFrame, "CENTER", 16, 8)
|
||||
nudgeFrame.yOffset = yOffset
|
||||
S:HandleEditBox(yOffset)
|
||||
|
||||
local resetButton = CreateFrame("Button", nudgeFrame:GetName().."ResetButton", nudgeFrame, "UIPanelButtonTemplate")
|
||||
resetButton:SetText(RESET)
|
||||
resetButton:Point("TOP", nudgeFrame, "CENTER", 0, 2)
|
||||
resetButton:Size(100, 25)
|
||||
resetButton:SetScript("OnClick", function()
|
||||
if ElvUIMoverNudgeWindow.child.textString then
|
||||
E:ResetMovers(ElvUIMoverNudgeWindow.child.textString)
|
||||
end
|
||||
end)
|
||||
S:HandleButton(resetButton)
|
||||
|
||||
local upButton = CreateFrame("Button", nudgeFrame:GetName().."UpButton", nudgeFrame)
|
||||
upButton:Point("BOTTOMRIGHT", nudgeFrame, "BOTTOM", -6, 4)
|
||||
upButton:SetScript("OnClick", function()
|
||||
E:NudgeMover(nil, 1)
|
||||
end)
|
||||
S:HandleNextPrevButton(upButton)
|
||||
upButton:SetSize(22, 22)
|
||||
|
||||
local downButton = CreateFrame("Button", nudgeFrame:GetName().."DownButton", nudgeFrame)
|
||||
downButton:Point("BOTTOMLEFT", nudgeFrame, "BOTTOM", 6, 4)
|
||||
downButton:SetScript("OnClick", function()
|
||||
E:NudgeMover(nil, -1)
|
||||
end)
|
||||
S:HandleNextPrevButton(downButton)
|
||||
downButton:SetSize(22, 22)
|
||||
|
||||
local leftButton = CreateFrame("Button", nudgeFrame:GetName().."LeftButton", nudgeFrame)
|
||||
leftButton:Point("RIGHT", upButton, "LEFT", -6, 0)
|
||||
leftButton:SetScript("OnClick", function()
|
||||
E:NudgeMover(-1)
|
||||
end)
|
||||
S:HandleNextPrevButton(leftButton)
|
||||
leftButton:SetSize(22, 22)
|
||||
|
||||
local rightButton = CreateFrame("Button", nudgeFrame:GetName().."RightButton", nudgeFrame)
|
||||
rightButton:Point("LEFT", downButton, "RIGHT", 6, 0)
|
||||
rightButton:SetScript("OnClick", function()
|
||||
E:NudgeMover(1)
|
||||
end)
|
||||
S:HandleNextPrevButton(rightButton)
|
||||
rightButton:SetSize(22, 22)
|
||||
end
|
||||
@@ -0,0 +1,320 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
|
||||
--Lua functions
|
||||
local next, ipairs, pairs = next, ipairs, pairs
|
||||
local floor, tinsert = math.floor, table.insert
|
||||
--WoW API / Variables
|
||||
local GetTime = GetTime
|
||||
local CreateFrame = CreateFrame
|
||||
local hooksecurefunc = hooksecurefunc
|
||||
|
||||
local ICON_SIZE = 36 --the normal size for an icon (don't change this)
|
||||
local FONT_SIZE = 20 --the base font size to use at a scale of 1
|
||||
local MIN_SCALE = 0.5 --the minimum scale we want to show cooldown counts at, anything below this will be hidden
|
||||
local MIN_DURATION = 1.5 --the minimum duration to show cooldown text for
|
||||
|
||||
function E:Cooldown_TextThreshold(cd, now)
|
||||
if cd.parent and cd.parent.textThreshold and cd.endTime then
|
||||
return (cd.endTime - now) >= cd.parent.textThreshold
|
||||
end
|
||||
end
|
||||
|
||||
function E:Cooldown_BelowScale(cd)
|
||||
if cd.parent then
|
||||
if cd.parent.hideText then return true end
|
||||
if cd.parent.skipScale then return end
|
||||
end
|
||||
|
||||
return cd.fontScale and (cd.fontScale < MIN_SCALE)
|
||||
end
|
||||
|
||||
function E:Cooldown_OnUpdate(elapsed)
|
||||
if self.nextUpdate > 0 then
|
||||
self.nextUpdate = self.nextUpdate - elapsed
|
||||
return
|
||||
end
|
||||
|
||||
if not E:Cooldown_IsEnabled(self) then
|
||||
E:Cooldown_StopTimer(self)
|
||||
else
|
||||
local now = GetTime()
|
||||
if self.endCooldown and now >= self.endCooldown then
|
||||
E:Cooldown_StopTimer(self)
|
||||
else
|
||||
if E:Cooldown_BelowScale(self) then
|
||||
self.text:SetText("")
|
||||
self.nextUpdate = 500
|
||||
elseif E:Cooldown_TextThreshold(self, now) then
|
||||
self.text:SetText("")
|
||||
self.nextUpdate = 1
|
||||
elseif self.endTime then
|
||||
local value, id, nextUpdate, remainder = E:GetTimeInfo(self.endTime - now, self.threshold, self.hhmmThreshold, self.mmssThreshold)
|
||||
self.nextUpdate = nextUpdate
|
||||
|
||||
local style = E.TimeFormats[id]
|
||||
if style then
|
||||
local which = (self.textColors and 2 or 1) + (self.showSeconds and 0 or 2)
|
||||
if self.textColors then
|
||||
self.text:SetFormattedText(style[which], value, self.textColors[id], remainder)
|
||||
else
|
||||
self.text:SetFormattedText(style[which], value, remainder)
|
||||
end
|
||||
end
|
||||
|
||||
local color = self.timeColors[id]
|
||||
if color then
|
||||
self.text:SetTextColor(color.r, color.g, color.b)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:Cooldown_OnSizeChanged(cd, width, force)
|
||||
local scale = width and (floor(width + 0.5) / ICON_SIZE)
|
||||
|
||||
-- dont bother updating when the fontScale is the same, unless we are passing the force arg
|
||||
if scale and (scale == cd.fontScale) and (force ~= true) then return end
|
||||
cd.fontScale = scale
|
||||
|
||||
-- this is needed because of skipScale variable, we wont allow a font size under the minscale
|
||||
if cd.fontScale and (cd.fontScale < MIN_SCALE) then
|
||||
scale = MIN_SCALE
|
||||
end
|
||||
|
||||
if cd.customFont then -- override font
|
||||
cd.text:FontTemplate(cd.customFont, (scale * cd.customFontSize), cd.customFontOutline)
|
||||
elseif scale then -- default, no override
|
||||
cd.text:FontTemplate(nil, (scale * FONT_SIZE), "OUTLINE")
|
||||
else -- this should never happen but just incase
|
||||
cd.text:FontTemplate()
|
||||
end
|
||||
|
||||
if E:Cooldown_BelowScale(cd) then
|
||||
cd:Hide()
|
||||
elseif cd.enabled then
|
||||
self:Cooldown_ForceUpdate(cd)
|
||||
end
|
||||
end
|
||||
|
||||
function E:Cooldown_IsEnabled(cd)
|
||||
if cd.forceEnabled then
|
||||
return true
|
||||
elseif cd.forceDisabled then
|
||||
return false
|
||||
elseif cd.reverseToggle ~= nil then
|
||||
return cd.reverseToggle
|
||||
else
|
||||
return E.db.cooldown.enable
|
||||
end
|
||||
end
|
||||
|
||||
function E:Cooldown_ForceUpdate(cd)
|
||||
cd.nextUpdate = -1
|
||||
cd:Show()
|
||||
end
|
||||
|
||||
function E:Cooldown_StopTimer(cd)
|
||||
cd.enabled = nil
|
||||
cd:Hide()
|
||||
end
|
||||
|
||||
function E:Cooldown_Options(timer, db, parent)
|
||||
local threshold, colors, icolors, hhmm, mmss, fonts
|
||||
if parent and db.override then
|
||||
threshold = db.threshold
|
||||
icolors = db.useIndicatorColor and E.TimeIndicatorColors[parent.CooldownOverride]
|
||||
colors = E.TimeColors[parent.CooldownOverride]
|
||||
end
|
||||
|
||||
if db.checkSeconds then
|
||||
hhmm, mmss = db.hhmmThreshold, db.mmssThreshold
|
||||
end
|
||||
|
||||
timer.timeColors = colors or E.TimeColors
|
||||
timer.threshold = threshold or E.db.cooldown.threshold or E.TimeThreshold
|
||||
timer.textColors = icolors or (E.db.cooldown.useIndicatorColor and E.TimeIndicatorColors)
|
||||
timer.hhmmThreshold = hhmm or (E.db.cooldown.checkSeconds and E.db.cooldown.hhmmThreshold)
|
||||
timer.mmssThreshold = mmss or (E.db.cooldown.checkSeconds and E.db.cooldown.mmssThreshold)
|
||||
|
||||
if db.reverse ~= nil then
|
||||
timer.reverseToggle = (E.db.cooldown.enable and not db.reverse) or (db.reverse and not E.db.cooldown.enable)
|
||||
else
|
||||
timer.reverseToggle = nil
|
||||
end
|
||||
|
||||
if timer.CooldownOverride ~= "auras" then
|
||||
if (db ~= E.db.cooldown) and db.fonts and db.fonts.enable then
|
||||
fonts = db.fonts -- custom fonts override default fonts
|
||||
elseif E.db.cooldown.fonts and E.db.cooldown.fonts.enable then
|
||||
fonts = E.db.cooldown.fonts -- default global font override
|
||||
end
|
||||
|
||||
if fonts and fonts.enable then
|
||||
timer.customFont = E.Libs.LSM:Fetch("font", fonts.font)
|
||||
timer.customFontSize = fonts.fontSize
|
||||
timer.customFontOutline = fonts.fontOutline
|
||||
else
|
||||
timer.customFont = nil
|
||||
timer.customFontSize = nil
|
||||
timer.customFontOutline = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:CreateCooldownTimer(parent)
|
||||
local timer = CreateFrame("Frame", parent:GetName() and "$parentTimer" or nil, parent)
|
||||
timer:SetFrameLevel(parent:GetFrameLevel() + 1)
|
||||
timer:Hide()
|
||||
timer:SetAllPoints()
|
||||
timer.parent = parent
|
||||
parent.timer = timer
|
||||
|
||||
local text = timer:CreateFontString(nil, "OVERLAY")
|
||||
text:Point("CENTER", 1, 1)
|
||||
text:SetJustifyH("CENTER")
|
||||
timer.text = text
|
||||
|
||||
-- can be used to modify elements created from this function
|
||||
if parent.CooldownPreHook then
|
||||
parent.CooldownPreHook(parent)
|
||||
end
|
||||
|
||||
-- cooldown override settings
|
||||
local db = (parent.CooldownOverride and E.db[parent.CooldownOverride]) or E.db
|
||||
if db and db.cooldown then
|
||||
E:Cooldown_Options(timer, db.cooldown, parent)
|
||||
end
|
||||
|
||||
-- keep an eye on the size so we can rescale the font if needed
|
||||
self:Cooldown_OnSizeChanged(timer, parent:GetWidth())
|
||||
parent:SetScript("OnSizeChanged", function(_, width)
|
||||
self:Cooldown_OnSizeChanged(timer, width)
|
||||
end)
|
||||
|
||||
-- keep this after Cooldown_OnSizeChanged
|
||||
timer:SetScript("OnUpdate", E.Cooldown_OnUpdate)
|
||||
|
||||
return timer
|
||||
end
|
||||
|
||||
E.RegisteredCooldowns = {}
|
||||
function E:OnSetCooldown(start, duration)
|
||||
if (not self.forceDisabled) and (start and duration) and (duration > MIN_DURATION) then
|
||||
local timer = self.timer or E:CreateCooldownTimer(self)
|
||||
timer.start = start
|
||||
timer.duration = duration
|
||||
timer.endTime = start + duration
|
||||
timer.endCooldown = timer.endTime - 0.05
|
||||
timer.nextUpdate = -1
|
||||
timer:Show()
|
||||
elseif self.timer then
|
||||
E:Cooldown_StopTimer(self.timer)
|
||||
end
|
||||
end
|
||||
|
||||
function E:RegisterCooldown(cooldown)
|
||||
if not cooldown.isHooked then
|
||||
hooksecurefunc(cooldown, "SetCooldown", E.OnSetCooldown)
|
||||
cooldown.isHooked = true
|
||||
end
|
||||
|
||||
if not cooldown.isRegisteredCooldown then
|
||||
local module = (cooldown.CooldownOverride or "global")
|
||||
if not E.RegisteredCooldowns[module] then E.RegisteredCooldowns[module] = {} end
|
||||
|
||||
tinsert(E.RegisteredCooldowns[module], cooldown)
|
||||
cooldown.isRegisteredCooldown = true
|
||||
end
|
||||
end
|
||||
|
||||
function E:GetCooldownColors(db)
|
||||
if not db then db = E.db.cooldown end -- just incase someone calls this without a first arg use the global
|
||||
local c13 = E:RGBToHex(db.hhmmColorIndicator.r, db.hhmmColorIndicator.g, db.hhmmColorIndicator.b) -- color for timers that are soon to expire
|
||||
local c12 = E:RGBToHex(db.mmssColorIndicator.r, db.mmssColorIndicator.g, db.mmssColorIndicator.b) -- color for timers that are soon to expire
|
||||
local c11 = E:RGBToHex(db.expireIndicator.r, db.expireIndicator.g, db.expireIndicator.b) -- color for timers that are soon to expire
|
||||
local c10 = E:RGBToHex(db.secondsIndicator.r, db.secondsIndicator.g, db.secondsIndicator.b) -- color for timers that have seconds remaining
|
||||
local c9 = E:RGBToHex(db.minutesIndicator.r, db.minutesIndicator.g, db.minutesIndicator.b) -- color for timers that have minutes remaining
|
||||
local c8 = E:RGBToHex(db.hoursIndicator.r, db.hoursIndicator.g, db.hoursIndicator.b) -- color for timers that have hours remaining
|
||||
local c7 = E:RGBToHex(db.daysIndicator.r, db.daysIndicator.g, db.daysIndicator.b) -- color for timers that have days remaining
|
||||
local c6 = db.hhmmColor -- HH:MM color
|
||||
local c5 = db.mmssColor -- MM:SS color
|
||||
local c4 = db.expiringColor -- color for timers that are soon to expire
|
||||
local c3 = db.secondsColor -- color for timers that have seconds remaining
|
||||
local c2 = db.minutesColor -- color for timers that have minutes remaining
|
||||
local c1 = db.hoursColor -- color for timers that have hours remaining
|
||||
local c0 = db.daysColor -- color for timers that have days remaining
|
||||
return c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13
|
||||
end
|
||||
|
||||
function E:UpdateCooldownOverride(module)
|
||||
local cooldowns = (module and E.RegisteredCooldowns[module])
|
||||
if (not cooldowns) or not next(cooldowns) then return end
|
||||
|
||||
for _, parent in ipairs(cooldowns) do
|
||||
local db = (parent.CooldownOverride and E.db[parent.CooldownOverride]) or self.db
|
||||
if db and db.cooldown then
|
||||
local timer = parent.isHooked and parent.isRegisteredCooldown and parent.timer
|
||||
local cd = timer or parent
|
||||
|
||||
-- cooldown override settings
|
||||
E:Cooldown_Options(cd, db.cooldown, parent)
|
||||
|
||||
-- update font on cooldowns
|
||||
if timer and cd then -- has a parent, these are timers from RegisterCooldown
|
||||
self:Cooldown_OnSizeChanged(cd, parent:GetWidth(), true)
|
||||
|
||||
elseif cd.text then
|
||||
if cd.customFont then
|
||||
cd.text:FontTemplate(cd.customFont, cd.customFontSize, cd.customFontOutline)
|
||||
elseif parent.CooldownOverride == "auras" then
|
||||
-- parent.auraType defined in `A:UpdateHeader` and `A:CreateIcon`
|
||||
local font = E.Libs.LSM:Fetch("font", db.font)
|
||||
if font and parent.auraType then
|
||||
local fontSize = db[parent.auraType] and db[parent.auraType].durationFontSize
|
||||
if fontSize then
|
||||
cd.text:FontTemplate(font, fontSize, db.fontOutline)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- force update top aura cooldowns
|
||||
if parent.CooldownOverride == "auras" then
|
||||
parent.nextUpdate = -1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:UpdateCooldownSettings(module)
|
||||
local db, timeColors, textColors = E.db.cooldown, E.TimeColors, E.TimeIndicatorColors
|
||||
|
||||
-- update the module timecolors if the config called it but ignore "global" and "all":
|
||||
-- global is the main call from config, all is the core file calls
|
||||
local isModule = module and (module ~= "global" and module ~= "all") and self.db[module] and self.db[module].cooldown
|
||||
if isModule then
|
||||
if not E.TimeColors[module] then E.TimeColors[module] = {} end
|
||||
if not E.TimeIndicatorColors[module] then E.TimeIndicatorColors[module] = {} end
|
||||
db, timeColors, textColors = self.db[module].cooldown, E.TimeColors[module], E.TimeIndicatorColors[module]
|
||||
end
|
||||
|
||||
timeColors[0], timeColors[1], timeColors[2], timeColors[3], timeColors[4], timeColors[5], timeColors[6], textColors[0], textColors[1], textColors[2], textColors[3], textColors[4], textColors[5], textColors[6] = self:GetCooldownColors(db)
|
||||
|
||||
if isModule then
|
||||
E:UpdateCooldownOverride(module)
|
||||
elseif module == "global" then -- this is only a call from the config change
|
||||
for key in pairs(E.RegisteredCooldowns) do
|
||||
E:UpdateCooldownOverride(key)
|
||||
end
|
||||
end
|
||||
|
||||
-- okay update the other override settings if it was one of the core file calls
|
||||
if module and (module == "all") then
|
||||
E:UpdateCooldownSettings("bags")
|
||||
E:UpdateCooldownSettings("nameplates")
|
||||
E:UpdateCooldownSettings("actionbar")
|
||||
E:UpdateCooldownSettings("unitframe")
|
||||
E:UpdateCooldownSettings("auras")
|
||||
end
|
||||
end
|
||||
+1211
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,602 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local D = E:GetModule("Distributor")
|
||||
local LibCompress = E.Libs.Compress
|
||||
local LibBase64 = E.Libs.Base64
|
||||
|
||||
--Lua functions
|
||||
local loadstring = loadstring
|
||||
local pcall = pcall
|
||||
local setfenv = setfenv
|
||||
local tonumber = tonumber
|
||||
local type = type
|
||||
local format, gsub, len, split, sub = string.format, string.gsub, string.len, string.split, string.sub
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local GetNumRaidMembers, UnitInRaid = GetNumRaidMembers, UnitInRaid
|
||||
local GetNumPartyMembers, UnitInParty = GetNumPartyMembers, UnitInParty
|
||||
local ACCEPT, CANCEL, YES, NO = ACCEPT, CANCEL, YES, NO
|
||||
|
||||
----------------------------------
|
||||
-- CONSTANTS
|
||||
----------------------------------
|
||||
|
||||
local REQUEST_PREFIX = "ELVUI_REQUEST"
|
||||
local REPLY_PREFIX = "ELVUI_REPLY"
|
||||
local TRANSFER_PREFIX = "ELVUI_TRANSFER"
|
||||
local TRANSFER_COMPLETE_PREFIX = "ELVUI_COMPLETE"
|
||||
|
||||
local ACECOMMPREFIXES = {
|
||||
[TRANSFER_PREFIX.."\001"] = true,
|
||||
[TRANSFER_PREFIX.."\002"] = true,
|
||||
[TRANSFER_PREFIX.."\003"] = true,
|
||||
}
|
||||
|
||||
-- The active downloads
|
||||
local Downloads = {}
|
||||
local Uploads = {}
|
||||
|
||||
function D:Initialize()
|
||||
self.Initialized = true
|
||||
self:RegisterComm(REQUEST_PREFIX)
|
||||
self:RegisterEvent("CHAT_MSG_ADDON")
|
||||
|
||||
self.statusBar = CreateFrame("StatusBar", "ElvUI_Download", E.UIParent)
|
||||
E:RegisterStatusBar(self.statusBar)
|
||||
self.statusBar:CreateBackdrop("Default")
|
||||
self.statusBar:SetStatusBarTexture(E.media.normTex)
|
||||
self.statusBar:SetStatusBarColor(0.95, 0.15, 0.15)
|
||||
self.statusBar:Size(250, 18)
|
||||
self.statusBar.text = self.statusBar:CreateFontString(nil, "OVERLAY")
|
||||
self.statusBar.text:FontTemplate()
|
||||
self.statusBar.text:Point("CENTER")
|
||||
self.statusBar:Hide()
|
||||
end
|
||||
|
||||
-- Used to start uploads
|
||||
function D:Distribute(target, otherServer, isGlobal)
|
||||
local profileKey, data
|
||||
if not isGlobal then
|
||||
if ElvDB.profileKeys then
|
||||
profileKey = ElvDB.profileKeys[E.myname.." - "..E.myrealm]
|
||||
end
|
||||
|
||||
data = ElvDB.profiles[profileKey]
|
||||
else
|
||||
profileKey = "global"
|
||||
data = ElvDB.global
|
||||
end
|
||||
|
||||
if not data or not profileKey then return end
|
||||
|
||||
data = E:RemoveTableDuplicates(data, isGlobal and G or P)
|
||||
|
||||
local serialData = self:Serialize(data)
|
||||
local length = len(serialData)
|
||||
local message = format("%s:%d:%s", profileKey, length, target)
|
||||
|
||||
Uploads[profileKey] = {
|
||||
serialData = serialData,
|
||||
target = target,
|
||||
}
|
||||
|
||||
if otherServer then
|
||||
local numParty, numRaid = GetNumPartyMembers(), GetNumRaidMembers()
|
||||
if numRaid > 0 and UnitInRaid("target") then
|
||||
self:SendCommMessage(REQUEST_PREFIX, message, "RAID")
|
||||
elseif numParty > 0 and UnitInParty("target") then
|
||||
self:SendCommMessage(REQUEST_PREFIX, message, "PARTY")
|
||||
else
|
||||
E:Print(L["Must be in group with the player if he isn't on the same server as you."])
|
||||
return
|
||||
end
|
||||
else
|
||||
self:SendCommMessage(REQUEST_PREFIX, message, "WHISPER", target)
|
||||
end
|
||||
self:RegisterComm(REPLY_PREFIX)
|
||||
E:StaticPopup_Show("DISTRIBUTOR_WAITING")
|
||||
end
|
||||
|
||||
function D:CHAT_MSG_ADDON(_, prefix, message, _, sender)
|
||||
if not ACECOMMPREFIXES[prefix] or not Downloads[sender] then return end
|
||||
|
||||
local cur = len(message)
|
||||
local max = Downloads[sender].length
|
||||
Downloads[sender].current = Downloads[sender].current + cur
|
||||
|
||||
if Downloads[sender].current > max then
|
||||
Downloads[sender].current = max
|
||||
end
|
||||
|
||||
self.statusBar:SetValue(Downloads[sender].current)
|
||||
end
|
||||
|
||||
function D:UpdateSendProgress(sentBytes, totalBytes)
|
||||
self.statusBar:SetValue(sentBytes)
|
||||
|
||||
if sentBytes == totalBytes then
|
||||
E:StaticPopupSpecial_Hide(self.statusBar)
|
||||
end
|
||||
end
|
||||
|
||||
function D:OnCommReceived(prefix, msg, dist, sender)
|
||||
if prefix == REQUEST_PREFIX then
|
||||
local profile, length, sendTo = split(":", msg)
|
||||
|
||||
if dist ~= "WHISPER" and sendTo ~= E.myname then
|
||||
return
|
||||
end
|
||||
|
||||
if self.statusBar:IsShown() then
|
||||
self:SendCommMessage(REPLY_PREFIX, profile..":NO", dist, sender)
|
||||
return
|
||||
end
|
||||
|
||||
local textString = format(L["%s is attempting to share the profile %s with you. Would you like to accept the request?"], sender, profile)
|
||||
if profile == "global" then
|
||||
textString = format(L["%s is attempting to share his filters with you. Would you like to accept the request?"], sender)
|
||||
end
|
||||
|
||||
E.PopupDialogs.DISTRIBUTOR_RESPONSE = {
|
||||
text = textString,
|
||||
OnAccept = function()
|
||||
self.statusBar:SetMinMaxValues(0, length)
|
||||
self.statusBar:SetValue(0)
|
||||
self.statusBar.text:SetFormattedText(L["Data From: %s"], sender)
|
||||
E:StaticPopupSpecial_Show(self.statusBar)
|
||||
self:SendCommMessage(REPLY_PREFIX, profile..":YES", dist, sender)
|
||||
end,
|
||||
OnCancel = function()
|
||||
self:SendCommMessage(REPLY_PREFIX, profile..":NO", dist, sender)
|
||||
end,
|
||||
button1 = ACCEPT,
|
||||
button2 = CANCEL,
|
||||
timeout = 32,
|
||||
whileDead = 1,
|
||||
hideOnEscape = 1
|
||||
}
|
||||
E:StaticPopup_Show("DISTRIBUTOR_RESPONSE")
|
||||
|
||||
Downloads[sender] = {
|
||||
current = 0,
|
||||
length = tonumber(length),
|
||||
profile = profile
|
||||
}
|
||||
|
||||
self:RegisterComm(TRANSFER_PREFIX)
|
||||
elseif prefix == REPLY_PREFIX then
|
||||
self:UnregisterComm(REPLY_PREFIX)
|
||||
E:StaticPopup_Hide("DISTRIBUTOR_WAITING")
|
||||
|
||||
local profileKey, response = split(":", msg)
|
||||
if response == "YES" then
|
||||
self.statusBar:SetMinMaxValues(0, len(Uploads[profileKey].serialData))
|
||||
self.statusBar:SetValue(0)
|
||||
self.statusBar.text:SetFormattedText(L["Data To: %s"], sender)
|
||||
E:StaticPopupSpecial_Show(self.statusBar)
|
||||
|
||||
self:RegisterComm(TRANSFER_COMPLETE_PREFIX)
|
||||
self:SendCommMessage(TRANSFER_PREFIX, Uploads[profileKey].serialData, dist, Uploads[profileKey].target, "BULK", self.UpdateSendProgress, self)
|
||||
Uploads[profileKey] = nil
|
||||
else
|
||||
E:StaticPopup_Show("DISTRIBUTOR_REQUEST_DENIED")
|
||||
Uploads[profileKey] = nil
|
||||
end
|
||||
elseif prefix == TRANSFER_PREFIX then
|
||||
self:UnregisterComm(TRANSFER_PREFIX)
|
||||
E:StaticPopupSpecial_Hide(self.statusBar)
|
||||
|
||||
local profileKey = Downloads[sender].profile
|
||||
local success, data = self:Deserialize(msg)
|
||||
|
||||
if success then
|
||||
local textString = format(L["Profile download complete from %s, would you like to load the profile %s now?"], sender, profileKey)
|
||||
|
||||
if profileKey == "global" then
|
||||
textString = format(L["Filter download complete from %s, would you like to apply changes now?"], sender)
|
||||
else
|
||||
if not ElvDB.profiles[profileKey] then
|
||||
ElvDB.profiles[profileKey] = data
|
||||
else
|
||||
textString = format(L["Profile download complete from %s, but the profile %s already exists. Change the name or else it will overwrite the existing profile."], sender, profileKey)
|
||||
E.PopupDialogs.DISTRIBUTOR_CONFIRM = {
|
||||
text = textString,
|
||||
button1 = ACCEPT,
|
||||
hasEditBox = 1,
|
||||
editBoxWidth = 350,
|
||||
maxLetters = 127,
|
||||
OnAccept = function(popup)
|
||||
ElvDB.profiles[popup.editBox:GetText()] = data
|
||||
E.Libs.AceAddon:GetAddon("ElvUI").data:SetProfile(popup.editBox:GetText())
|
||||
E:UpdateAll(true)
|
||||
Downloads[sender] = nil
|
||||
E:StaticPopup_Show("CONFIG_RL")
|
||||
end,
|
||||
OnShow = function(popup) popup.editBox:SetText(profileKey) popup.editBox:SetFocus() end,
|
||||
timeout = 0,
|
||||
exclusive = 1,
|
||||
whileDead = 1,
|
||||
hideOnEscape = 1,
|
||||
preferredIndex = 3
|
||||
}
|
||||
|
||||
E:StaticPopup_Show("DISTRIBUTOR_CONFIRM")
|
||||
self:SendCommMessage(TRANSFER_COMPLETE_PREFIX, "COMPLETE", dist, sender)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
E.PopupDialogs.DISTRIBUTOR_CONFIRM = {
|
||||
text = textString,
|
||||
OnAccept = function()
|
||||
if profileKey == "global" then
|
||||
E:CopyTable(ElvDB.global, data)
|
||||
E:UpdateAll(true)
|
||||
else
|
||||
E.Libs.AceAddon:GetAddon("ElvUI").data:SetProfile(profileKey)
|
||||
end
|
||||
Downloads[sender] = nil
|
||||
end,
|
||||
OnCancel = function()
|
||||
Downloads[sender] = nil
|
||||
end,
|
||||
button1 = YES,
|
||||
button2 = NO,
|
||||
whileDead = 1,
|
||||
hideOnEscape = 1
|
||||
}
|
||||
|
||||
E:StaticPopup_Show("DISTRIBUTOR_CONFIRM")
|
||||
self:SendCommMessage(TRANSFER_COMPLETE_PREFIX, "COMPLETE", dist, sender)
|
||||
else
|
||||
E:StaticPopup_Show("DISTRIBUTOR_FAILED")
|
||||
self:SendCommMessage(TRANSFER_COMPLETE_PREFIX, "FAILED", dist, sender)
|
||||
end
|
||||
elseif prefix == TRANSFER_COMPLETE_PREFIX then
|
||||
self:UnregisterComm(TRANSFER_COMPLETE_PREFIX)
|
||||
if msg == "COMPLETE" then
|
||||
E:StaticPopup_Show("DISTRIBUTOR_SUCCESS")
|
||||
else
|
||||
E:StaticPopup_Show("DISTRIBUTOR_FAILED")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Keys that should not be exported
|
||||
local blacklistedKeys = {
|
||||
profile = {
|
||||
general = {
|
||||
numberPrefixStyle = true,
|
||||
}
|
||||
},
|
||||
private = {},
|
||||
global = {
|
||||
general = {
|
||||
UIScale = true,
|
||||
locale = true,
|
||||
eyefinity = true,
|
||||
ignoreScalePopup = true
|
||||
},
|
||||
chat = {
|
||||
classColorMentionExcludedNames = true
|
||||
},
|
||||
unitframe = {
|
||||
spellRangeCheck = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local function GetProfileData(profileType)
|
||||
if not profileType or type(profileType) ~= "string" then
|
||||
E:Print("Bad argument #1 to 'GetProfileData' (string expected)")
|
||||
return
|
||||
end
|
||||
|
||||
local profileKey
|
||||
local profileData = {}
|
||||
|
||||
if profileType == "profile" then
|
||||
if ElvDB.profileKeys then
|
||||
profileKey = ElvDB.profileKeys[E.myname.." - "..E.myrealm]
|
||||
end
|
||||
|
||||
--Copy current profile data
|
||||
profileData = E:CopyTable(profileData, ElvDB.profiles[profileKey])
|
||||
--This table will also hold all default values, not just the changed settings.
|
||||
--This makes the table huge, and will cause the WoW client to lock up for several seconds.
|
||||
--We compare against the default table and remove all duplicates from our table. The table is now much smaller.
|
||||
profileData = E:RemoveTableDuplicates(profileData, P)
|
||||
profileData = E:FilterTableFromBlacklist(profileData, blacklistedKeys.profile)
|
||||
elseif profileType == "private" then
|
||||
local privateProfileKey = E.myname.." - "..E.myrealm
|
||||
profileKey = "private"
|
||||
|
||||
profileData = E:CopyTable(profileData, ElvPrivateDB.profiles[privateProfileKey])
|
||||
profileData = E:RemoveTableDuplicates(profileData, V)
|
||||
profileData = E:FilterTableFromBlacklist(profileData, blacklistedKeys.private)
|
||||
elseif profileType == "global" then
|
||||
profileKey = "global"
|
||||
|
||||
profileData = E:CopyTable(profileData, ElvDB.global)
|
||||
profileData = E:RemoveTableDuplicates(profileData, G)
|
||||
profileData = E:FilterTableFromBlacklist(profileData, blacklistedKeys.global)
|
||||
elseif profileType == "filters" then
|
||||
profileKey = "filters"
|
||||
|
||||
profileData.unitframe = {}
|
||||
profileData.unitframe.aurafilters = {}
|
||||
profileData.unitframe.aurafilters = E:CopyTable(profileData.unitframe.aurafilters, ElvDB.global.unitframe.aurafilters)
|
||||
profileData.unitframe.buffwatch = {}
|
||||
profileData.unitframe.buffwatch = E:CopyTable(profileData.unitframe.buffwatch, ElvDB.global.unitframe.buffwatch)
|
||||
profileData = E:RemoveTableDuplicates(profileData, G)
|
||||
elseif profileType == "styleFilters" then
|
||||
profileKey = "styleFilters"
|
||||
|
||||
profileData.nameplates = {}
|
||||
profileData.nameplates.filters = {}
|
||||
profileData.nameplates.filters = E:CopyTable(profileData.nameplates.filters, ElvDB.global.nameplates.filters)
|
||||
profileData = E:RemoveTableDuplicates(profileData, G)
|
||||
end
|
||||
|
||||
return profileKey, profileData
|
||||
end
|
||||
|
||||
local function GetProfileExport(profileType, exportFormat)
|
||||
local profileExport, exportString
|
||||
local profileKey, profileData = GetProfileData(profileType)
|
||||
|
||||
if not profileKey or not profileData or (profileData and type(profileData) ~= "table") then
|
||||
E:Print("Error getting data from 'GetProfileData'")
|
||||
return
|
||||
end
|
||||
|
||||
if exportFormat == "text" then
|
||||
local serialData = D:Serialize(profileData)
|
||||
exportString = D:CreateProfileExport(serialData, profileType, profileKey)
|
||||
local compressedData = LibCompress:Compress(exportString)
|
||||
local encodedData = LibBase64:Encode(compressedData)
|
||||
profileExport = encodedData
|
||||
elseif exportFormat == "luaTable" then
|
||||
exportString = E:TableToLuaString(profileData)
|
||||
profileExport = D:CreateProfileExport(exportString, profileType, profileKey)
|
||||
elseif exportFormat == "luaPlugin" then
|
||||
profileExport = E:ProfileTableToPluginFormat(profileData, profileType)
|
||||
end
|
||||
|
||||
return profileKey, profileExport
|
||||
end
|
||||
|
||||
function D:CreateProfileExport(dataString, profileType, profileKey)
|
||||
local returnString
|
||||
|
||||
if profileType == "profile" then
|
||||
returnString = format("%s::%s::%s", dataString, profileType, profileKey)
|
||||
else
|
||||
returnString = format("%s::%s", dataString, profileType)
|
||||
end
|
||||
|
||||
return returnString
|
||||
end
|
||||
|
||||
function D:GetImportStringType(dataString)
|
||||
local stringType = ""
|
||||
|
||||
if LibBase64:IsBase64(dataString) then
|
||||
stringType = "Base64"
|
||||
elseif sub(dataString, 1, 1) == "{" then --Basic check to weed out obviously wrong strings
|
||||
stringType = "Table"
|
||||
end
|
||||
|
||||
return stringType
|
||||
end
|
||||
|
||||
function D:Decode(dataString)
|
||||
local profileInfo, profileType, profileKey, profileData
|
||||
local stringType = self:GetImportStringType(dataString)
|
||||
|
||||
if stringType == "Base64" then
|
||||
local decodedData = LibBase64:Decode(dataString)
|
||||
local decompressedData, decompressedMessage = LibCompress:Decompress(decodedData)
|
||||
|
||||
if not decompressedData then
|
||||
E:Print("Error decompressing data:", decompressedMessage)
|
||||
return
|
||||
end
|
||||
|
||||
local serializedData, success
|
||||
serializedData, profileInfo = E:SplitString(decompressedData, "^^::") -- "^^" indicates the end of the AceSerializer string
|
||||
|
||||
if not profileInfo then
|
||||
E:Print("Error importing profile. String is invalid or corrupted!")
|
||||
return
|
||||
end
|
||||
|
||||
serializedData = format("%s%s", serializedData, "^^") --Add back the AceSerializer terminator
|
||||
profileType, profileKey = E:SplitString(profileInfo, "::")
|
||||
success, profileData = D:Deserialize(serializedData)
|
||||
|
||||
if not success then
|
||||
E:Print("Error deserializing:", profileData)
|
||||
return
|
||||
end
|
||||
elseif stringType == "Table" then
|
||||
local profileDataAsString
|
||||
profileDataAsString, profileInfo = E:SplitString(dataString, "}::") -- "}::" indicates the end of the table
|
||||
|
||||
if not profileInfo then
|
||||
E:Print("Error extracting profile info. Invalid import string!")
|
||||
return
|
||||
end
|
||||
|
||||
if not profileDataAsString then
|
||||
E:Print("Error extracting profile data. Invalid import string!")
|
||||
return
|
||||
end
|
||||
|
||||
profileDataAsString = format("%s%s", profileDataAsString, "}") --Add back the missing "}"
|
||||
profileDataAsString = gsub(profileDataAsString, "\124\124", "\124") --Remove escape pipe characters
|
||||
profileType, profileKey = E:SplitString(profileInfo, "::")
|
||||
|
||||
local func, err = loadstring(format("%s %s", "return", profileDataAsString))
|
||||
|
||||
if func then
|
||||
setfenv(func, {}) -- execute code in an empty environment
|
||||
local success, res = pcall(func)
|
||||
|
||||
if success then
|
||||
profileData = res
|
||||
else
|
||||
err = res
|
||||
end
|
||||
end
|
||||
|
||||
if err then
|
||||
E:Print("Error converting lua string to table:", err)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return profileType, profileKey, profileData
|
||||
end
|
||||
|
||||
local function SetImportedProfile(profileType, profileKey, profileData, force)
|
||||
D.profileType = nil
|
||||
D.profileKey = nil
|
||||
D.profileData = nil
|
||||
|
||||
if profileType == "profile" then
|
||||
profileData = E:FilterTableFromBlacklist(profileData, blacklistedKeys.profile) --Remove unwanted options from import
|
||||
if not ElvDB.profiles[profileKey] or force then
|
||||
if force and E.data.keys.profile == profileKey then
|
||||
--Overwriting an active profile doesn't update when calling SetProfile
|
||||
--So make it look like we use a different profile
|
||||
local tempKey = profileKey.."_Temp"
|
||||
E.data.keys.profile = tempKey
|
||||
end
|
||||
ElvDB.profiles[profileKey] = profileData
|
||||
--Calling SetProfile will now update all settings correctly
|
||||
E.data:SetProfile(profileKey)
|
||||
else
|
||||
D.profileType = profileType
|
||||
D.profileKey = profileKey
|
||||
D.profileData = profileData
|
||||
E:StaticPopup_Show("IMPORT_PROFILE_EXISTS")
|
||||
|
||||
return
|
||||
end
|
||||
elseif profileType == "private" then
|
||||
profileData = E:FilterTableFromBlacklist(profileData, blacklistedKeys.private) --Remove unwanted options from import
|
||||
local pfKey = ElvPrivateDB.profileKeys[E.myname.." - "..E.myrealm]
|
||||
ElvPrivateDB.profiles[pfKey] = profileData
|
||||
E:StaticPopup_Show("IMPORT_RL")
|
||||
elseif profileType == "global" then
|
||||
profileData = E:FilterTableFromBlacklist(profileData, blacklistedKeys.global) --Remove unwanted options from import
|
||||
E:CopyTable(ElvDB.global, profileData)
|
||||
E:StaticPopup_Show("IMPORT_RL")
|
||||
elseif profileType == "filters" then
|
||||
E:CopyTable(ElvDB.global.unitframe, profileData.unitframe)
|
||||
elseif profileType == "styleFilters" then
|
||||
E:CopyTable(ElvDB.global.nameplates, profileData.nameplates)
|
||||
end
|
||||
|
||||
--Update all ElvUI modules
|
||||
E:UpdateAll(true)
|
||||
end
|
||||
|
||||
function D:ExportProfile(profileType, exportFormat)
|
||||
if not profileType or not exportFormat then
|
||||
E:Print("Bad argument to 'ExportProfile' (string expected)")
|
||||
return
|
||||
end
|
||||
|
||||
local profileKey, profileExport = GetProfileExport(profileType, exportFormat)
|
||||
|
||||
return profileKey, profileExport
|
||||
end
|
||||
|
||||
function D:ImportProfile(dataString)
|
||||
local profileType, profileKey, profileData = self:Decode(dataString)
|
||||
|
||||
if not profileData or type(profileData) ~= "table" then
|
||||
E:Print("Error: something went wrong when converting string to table!")
|
||||
return
|
||||
end
|
||||
|
||||
if profileType and ((profileType == "profile" and profileKey) or profileType ~= "profile") then
|
||||
SetImportedProfile(profileType, profileKey, profileData)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
E.PopupDialogs.DISTRIBUTOR_SUCCESS = {
|
||||
text = L["Your profile was successfully recieved by the player."],
|
||||
whileDead = 1,
|
||||
hideOnEscape = 1,
|
||||
button1 = OKAY
|
||||
}
|
||||
|
||||
E.PopupDialogs.DISTRIBUTOR_WAITING = {
|
||||
text = L["Profile request sent. Waiting for response from player."],
|
||||
whileDead = 1,
|
||||
hideOnEscape = 1,
|
||||
timeout = 35
|
||||
}
|
||||
|
||||
E.PopupDialogs.DISTRIBUTOR_REQUEST_DENIED = {
|
||||
text = L["Request was denied by user."],
|
||||
whileDead = 1,
|
||||
hideOnEscape = 1,
|
||||
button1 = OKAY
|
||||
}
|
||||
|
||||
E.PopupDialogs.DISTRIBUTOR_FAILED = {
|
||||
text = L["Lord! It's a miracle! The download up and vanished like a fart in the wind! Try Again!"],
|
||||
whileDead = 1,
|
||||
hideOnEscape = 1,
|
||||
button1 = OKAY
|
||||
}
|
||||
|
||||
E.PopupDialogs.DISTRIBUTOR_RESPONSE = {}
|
||||
E.PopupDialogs.DISTRIBUTOR_CONFIRM = {}
|
||||
|
||||
E.PopupDialogs.IMPORT_PROFILE_EXISTS = {
|
||||
text = L["The profile you tried to import already exists. Choose a new name or accept to overwrite the existing profile."],
|
||||
button1 = ACCEPT,
|
||||
button2 = CANCEL,
|
||||
hasEditBox = 1,
|
||||
editBoxWidth = 350,
|
||||
maxLetters = 127,
|
||||
OnAccept = function(self)
|
||||
local profileType = D.profileType
|
||||
local profileKey = self.editBox:GetText()
|
||||
local profileData = D.profileData
|
||||
SetImportedProfile(profileType, profileKey, profileData, true)
|
||||
end,
|
||||
EditBoxOnTextChanged = function(self)
|
||||
if self:GetText() == "" then
|
||||
self:GetParent().button1:Disable()
|
||||
else
|
||||
self:GetParent().button1:Enable()
|
||||
end
|
||||
end,
|
||||
OnShow = function(self) self.editBox:SetText(D.profileKey) self.editBox:SetFocus() end,
|
||||
whileDead = 1,
|
||||
hideOnEscape = true,
|
||||
preferredIndex = 3
|
||||
}
|
||||
|
||||
E.PopupDialogs.IMPORT_RL = {
|
||||
text = L["You have imported settings which may require a UI reload to take effect. Reload now?"],
|
||||
button1 = ACCEPT,
|
||||
button2 = CANCEL,
|
||||
OnAccept = ReloadUI,
|
||||
whileDead = 1,
|
||||
hideOnEscape = false,
|
||||
preferredIndex = 3
|
||||
}
|
||||
|
||||
local function InitializeCallback()
|
||||
D:Initialize()
|
||||
end
|
||||
|
||||
E:RegisterModule(D:GetName(), InitializeCallback)
|
||||
@@ -0,0 +1,88 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
|
||||
--Lua functions
|
||||
local tinsert = tinsert
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local ToggleFrame = ToggleFrame
|
||||
local GetCursorPosition = GetCursorPosition
|
||||
|
||||
local PADDING = 10
|
||||
local BUTTON_HEIGHT = 16
|
||||
local BUTTON_WIDTH = 135
|
||||
|
||||
local function OnClick(btn)
|
||||
btn.func()
|
||||
|
||||
btn:GetParent():Hide()
|
||||
end
|
||||
|
||||
local function OnEnter(btn)
|
||||
btn.hoverTex:Show()
|
||||
end
|
||||
|
||||
local function OnLeave(btn)
|
||||
btn.hoverTex:Hide()
|
||||
end
|
||||
|
||||
function E:DropDown(list, frame, xOffset, yOffset)
|
||||
if not frame.buttons then
|
||||
frame.buttons = {}
|
||||
frame:SetFrameStrata("DIALOG")
|
||||
frame:SetClampedToScreen(true)
|
||||
tinsert(UISpecialFrames, frame:GetName())
|
||||
frame:Hide()
|
||||
end
|
||||
|
||||
xOffset = xOffset or 0
|
||||
yOffset = yOffset or 0
|
||||
|
||||
for i = 1, #frame.buttons do
|
||||
frame.buttons[i]:Hide()
|
||||
end
|
||||
|
||||
for i = 1, #list do
|
||||
if not frame.buttons[i] then
|
||||
frame.buttons[i] = CreateFrame("Button", nil, frame)
|
||||
|
||||
frame.buttons[i].hoverTex = frame.buttons[i]:CreateTexture(nil, "OVERLAY")
|
||||
frame.buttons[i].hoverTex:SetAllPoints()
|
||||
frame.buttons[i].hoverTex:SetTexture([[Interface\QuestFrame\UI-QuestTitleHighlight]])
|
||||
frame.buttons[i].hoverTex:SetBlendMode("ADD")
|
||||
frame.buttons[i].hoverTex:Hide()
|
||||
|
||||
frame.buttons[i].text = frame.buttons[i]:CreateFontString(nil, "BORDER")
|
||||
frame.buttons[i].text:SetAllPoints()
|
||||
frame.buttons[i].text:FontTemplate()
|
||||
frame.buttons[i].text:SetJustifyH("LEFT")
|
||||
|
||||
frame.buttons[i]:SetScript("OnEnter", OnEnter)
|
||||
frame.buttons[i]:SetScript("OnLeave", OnLeave)
|
||||
end
|
||||
|
||||
frame.buttons[i]:Show()
|
||||
frame.buttons[i]:Height(BUTTON_HEIGHT)
|
||||
frame.buttons[i]:Width(BUTTON_WIDTH)
|
||||
frame.buttons[i].text:SetText(list[i].text)
|
||||
frame.buttons[i].func = list[i].func
|
||||
frame.buttons[i]:SetScript("OnClick", OnClick)
|
||||
|
||||
if i == 1 then
|
||||
frame.buttons[i]:Point("TOPLEFT", frame, "TOPLEFT", PADDING, -PADDING)
|
||||
else
|
||||
frame.buttons[i]:Point("TOPLEFT", frame.buttons[i-1], "BOTTOMLEFT")
|
||||
end
|
||||
end
|
||||
|
||||
frame:Height((#list * BUTTON_HEIGHT) + PADDING * 2)
|
||||
frame:Width(BUTTON_WIDTH + PADDING * 2)
|
||||
|
||||
local UIScale = UIParent:GetScale()
|
||||
local x, y = GetCursorPosition()
|
||||
x = x/UIScale
|
||||
y = y/UIScale
|
||||
frame:ClearAllPoints()
|
||||
frame:Point("TOPLEFT", UIParent, "BOTTOMLEFT", x + xOffset, y + yOffset)
|
||||
|
||||
ToggleFrame(frame)
|
||||
end
|
||||
@@ -0,0 +1,99 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local LSM = E.Libs.LSM
|
||||
|
||||
--Lua functions
|
||||
--WoW API / Variables
|
||||
local SetCVar = SetCVar
|
||||
|
||||
local function SetFont(obj, font, size, style, sr, sg, sb, sa, sox, soy, r, g, b)
|
||||
if not obj then return end
|
||||
|
||||
obj:SetFont(font, size, style)
|
||||
if sr and sg and sb then obj:SetShadowColor(sr, sg, sb, sa) end
|
||||
if sox and soy then obj:SetShadowOffset(sox, soy) end
|
||||
if r and g and b then obj:SetTextColor(r, g, b)
|
||||
elseif r then obj:SetAlpha(r) end
|
||||
end
|
||||
|
||||
function E:UpdateBlizzardFonts()
|
||||
local NORMAL = self.media.normFont
|
||||
local NUMBER = self.media.normFont
|
||||
local COMBAT = LSM:Fetch("font", self.private.general.dmgfont)
|
||||
local NAMEFONT = LSM:Fetch("font", self.private.general.namefont)
|
||||
local MONOCHROME = ""
|
||||
|
||||
UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT = 12
|
||||
CHAT_FONT_HEIGHTS = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
|
||||
|
||||
if self.db.general.font == "Homespun" then
|
||||
MONOCHROME = "MONOCHROME"
|
||||
end
|
||||
|
||||
if self.eyefinity then
|
||||
InterfaceOptionsCombatTextPanelTargetDamage:Hide()
|
||||
InterfaceOptionsCombatTextPanelPeriodicDamage:Hide()
|
||||
InterfaceOptionsCombatTextPanelPetDamage:Hide()
|
||||
InterfaceOptionsCombatTextPanelHealing:Hide()
|
||||
SetCVar("CombatLogPeriodicSpells", 0)
|
||||
SetCVar("PetMeleeDamage", 0)
|
||||
SetCVar("CombatDamage", 0)
|
||||
SetCVar("CombatHealing", 0)
|
||||
|
||||
-- set an invisible font for xp, honor kill, etc
|
||||
COMBAT = E.Media.Fonts.Invisible
|
||||
end
|
||||
|
||||
UNIT_NAME_FONT = NAMEFONT
|
||||
NAMEPLATE_FONT = NAMEFONT
|
||||
DAMAGE_TEXT_FONT = COMBAT
|
||||
STANDARD_TEXT_FONT = NORMAL
|
||||
|
||||
if self.private.general.replaceBlizzFonts then
|
||||
SetFont(GameTooltipHeader, NORMAL, self.db.general.fontSize)
|
||||
SetFont(NumberFont_OutlineThick_Mono_Small, NUMBER, self.db.general.fontSize, "OUTLINE")
|
||||
SetFont(NumberFont_Outline_Huge, NUMBER, 28, MONOCHROME.."THICKOUTLINE", 28)
|
||||
SetFont(NumberFont_Outline_Large, NUMBER, 15, MONOCHROME.."OUTLINE")
|
||||
SetFont(NumberFont_Outline_Med, NUMBER, self.db.general.fontSize, "OUTLINE")
|
||||
SetFont(NumberFont_Shadow_Med, NORMAL, self.db.general.fontSize)
|
||||
SetFont(NumberFont_Shadow_Small, NORMAL, self.db.general.fontSize)
|
||||
SetFont(ChatFontSmall, NORMAL, self.db.general.fontSize)
|
||||
SetFont(QuestFontHighlight, NORMAL, self.db.general.fontSize)
|
||||
SetFont(QuestFont, NORMAL, self.db.general.fontSize)
|
||||
SetFont(QuestFont_Large, NORMAL, 14)
|
||||
SetFont(QuestTitleFont, NORMAL, self.db.general.fontSize + 8)
|
||||
SetFont(QuestTitleFontBlackShadow, NORMAL, self.db.general.fontSize + 8)
|
||||
SetFont(SystemFont_Large, NORMAL, 15)
|
||||
SetFont(GameFontNormalMed3, NORMAL, 15)
|
||||
SetFont(SystemFont_Shadow_Huge1, NORMAL, 20, MONOCHROME.."OUTLINE")
|
||||
SetFont(SystemFont_Med1, NORMAL, self.db.general.fontSize)
|
||||
SetFont(SystemFont_Med3, NORMAL, self.db.general.fontSize)
|
||||
SetFont(SystemFont_OutlineThick_Huge2, NORMAL, 20, MONOCHROME.."THICKOUTLINE")
|
||||
SetFont(SystemFont_Outline_Small, NUMBER, self.db.general.fontSize, "OUTLINE")
|
||||
SetFont(SystemFont_Shadow_Large, NORMAL, 15)
|
||||
SetFont(SystemFont_Shadow_Med1, NORMAL, self.db.general.fontSize)
|
||||
SetFont(SystemFont_Shadow_Med3, NORMAL, self.db.general.fontSize)
|
||||
SetFont(SystemFont_Shadow_Outline_Huge2, NORMAL, 20, MONOCHROME.."OUTLINE")
|
||||
SetFont(SystemFont_Shadow_Small, NORMAL, self.db.general.fontSize)
|
||||
SetFont(SystemFont_Small, NORMAL, self.db.general.fontSize)
|
||||
SetFont(SystemFont_Tiny, NORMAL, self.db.general.fontSize)
|
||||
SetFont(Tooltip_Med, NORMAL, self.db.general.fontSize)
|
||||
SetFont(Tooltip_Small, NORMAL, self.db.general.fontSize)
|
||||
SetFont(FriendsFont_Normal, NORMAL, self.db.general.fontSize)
|
||||
SetFont(FriendsFont_Small, NORMAL, self.db.general.fontSize)
|
||||
SetFont(FriendsFont_Large, NORMAL, self.db.general.fontSize)
|
||||
SetFont(FriendsFont_UserText, NORMAL, self.db.general.fontSize)
|
||||
SetFont(SpellFont_Small, NORMAL, self.db.general.fontSize*0.9)
|
||||
SetFont(ZoneTextString, NORMAL, 32, MONOCHROME.."OUTLINE")
|
||||
SetFont(SubZoneTextString, NORMAL, 25, MONOCHROME.."OUTLINE")
|
||||
SetFont(PVPInfoTextString, NORMAL, 22, MONOCHROME.."OUTLINE")
|
||||
SetFont(PVPArenaTextString, NORMAL, 22, MONOCHROME.."OUTLINE")
|
||||
SetFont(CombatTextFont, COMBAT, 100, MONOCHROME.."OUTLINE")
|
||||
SetFont(SystemFont_OutlineThick_WTF, NORMAL, 32, MONOCHROME.."OUTLINE")
|
||||
SetFont(SubZoneTextFont, NORMAL, 24, MONOCHROME.."OUTLINE")
|
||||
SetFont(MailFont_Large, NORMAL, 14)
|
||||
SetFont(InvoiceFont_Med, NORMAL, 12)
|
||||
SetFont(InvoiceFont_Small, NORMAL, self.db.general.fontSize)
|
||||
SetFont(AchievementFont_Small, NORMAL, self.db.general.fontSize)
|
||||
SetFont(ReputationDetailFont, NORMAL, self.db.general.fontSize)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,936 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local UF = E:GetModule("UnitFrames")
|
||||
local S = E:GetModule("Skins")
|
||||
|
||||
--Lua functions
|
||||
local _G = _G
|
||||
local format = format
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local SetCVar = SetCVar
|
||||
local PlaySoundFile = PlaySoundFile
|
||||
local ReloadUI = ReloadUI
|
||||
local UIFrameFadeOut = UIFrameFadeOut
|
||||
local ChatFrame_AddMessageGroup = ChatFrame_AddMessageGroup
|
||||
local ChatFrame_RemoveAllMessageGroups = ChatFrame_RemoveAllMessageGroups
|
||||
local ChatFrame_AddChannel = ChatFrame_AddChannel
|
||||
local ChatFrame_RemoveChannel = ChatFrame_RemoveChannel
|
||||
local ChangeChatColor = ChangeChatColor
|
||||
local ToggleChatColorNamesByClassGroup = ToggleChatColorNamesByClassGroup
|
||||
local FCF_ResetChatWindows = FCF_ResetChatWindows
|
||||
local FCF_SetLocked = FCF_SetLocked
|
||||
local FCF_DockFrame, FCF_UnDockFrame = FCF_DockFrame, FCF_UnDockFrame
|
||||
local FCF_OpenNewWindow = FCF_OpenNewWindow
|
||||
local FCF_SavePositionAndDimensions = FCF_SavePositionAndDimensions
|
||||
local FCF_SetWindowName = FCF_SetWindowName
|
||||
local FCF_StopDragging = FCF_StopDragging
|
||||
local FCF_SetChatWindowFontSize = FCF_SetChatWindowFontSize
|
||||
local CLASS, CONTINUE, PREVIOUS = CLASS, CONTINUE, PREVIOUS
|
||||
local NUM_CHAT_WINDOWS = NUM_CHAT_WINDOWS
|
||||
local LOOT, GENERAL, TRADE, GUILD, WHISPER = LOOT, GENERAL, TRADE, GUILD, WHISPER
|
||||
local GUILD_EVENT_LOG = GUILD_EVENT_LOG
|
||||
|
||||
local CURRENT_PAGE = 0
|
||||
local MAX_PAGE = 8
|
||||
|
||||
local function SetupChat(noDisplayMsg)
|
||||
FCF_ResetChatWindows() -- Monitor this
|
||||
FCF_SetLocked(ChatFrame1, 1)
|
||||
FCF_DockFrame(ChatFrame2)
|
||||
FCF_SetLocked(ChatFrame2, 1)
|
||||
|
||||
FCF_OpenNewWindow(LOOT)
|
||||
FCF_UnDockFrame(ChatFrame3)
|
||||
FCF_SetLocked(ChatFrame3, 1)
|
||||
ChatFrame3:Show()
|
||||
|
||||
FCF_OpenNewWindow(GUILD)
|
||||
FCF_OpenNewWindow(WHISPER)
|
||||
FCF_DockFrame(ChatFrame4)
|
||||
FCF_SetLocked(ChatFrame4, 1)
|
||||
FCF_DockFrame(ChatFrame5)
|
||||
FCF_SetLocked(ChatFrame5, 1)
|
||||
|
||||
FCF_SelectDockFrame(ChatFrame1)
|
||||
|
||||
for i = 1, NUM_CHAT_WINDOWS do
|
||||
local frame = _G[format("ChatFrame%s", i)]
|
||||
|
||||
-- move general bottom left
|
||||
if i == 1 then
|
||||
frame:ClearAllPoints()
|
||||
frame:Point("BOTTOMLEFT", LeftChatToggleButton, "TOPLEFT", 1, 3)
|
||||
elseif i == 3 then
|
||||
frame:ClearAllPoints()
|
||||
frame:Point("BOTTOMLEFT", RightChatDataPanel, "TOPLEFT", 1, 3)
|
||||
end
|
||||
|
||||
FCF_SavePositionAndDimensions(frame)
|
||||
FCF_StopDragging(frame)
|
||||
|
||||
-- set default Elvui font size
|
||||
FCF_SetChatWindowFontSize(nil, frame, 12)
|
||||
|
||||
-- rename windows general because moved to chat #3
|
||||
if i == 1 then
|
||||
FCF_SetWindowName(frame, GENERAL)
|
||||
elseif i == 2 then
|
||||
FCF_SetWindowName(frame, GUILD_EVENT_LOG)
|
||||
elseif i == 3 then
|
||||
FCF_SetWindowName(frame, LOOT.." / "..TRADE)
|
||||
elseif i == 4 then
|
||||
FCF_SetWindowName(frame, GUILD)
|
||||
elseif i == 5 then
|
||||
FCF_SetWindowName(frame, WHISPER)
|
||||
end
|
||||
end
|
||||
|
||||
local chatGroup = {"SYSTEM", "CHANNEL", "SAY", "EMOTE", "YELL", "WHISPER", "PARTY", "PARTY_LEADER", "RAID", "RAID_LEADER", "RAID_WARNING", "BATTLEGROUND", "BATTLEGROUND_LEADER", "GUILD", "OFFICER", "MONSTER_SAY", "MONSTER_YELL", "MONSTER_EMOTE", "MONSTER_WHISPER", "MONSTER_BOSS_EMOTE", "MONSTER_BOSS_WHISPER", "ERRORS", "AFK", "DND", "IGNORED", "BG_HORDE", "BG_ALLIANCE", "BG_NEUTRAL", "ACHIEVEMENT", "GUILD_ACHIEVEMENT", "BN_WHISPER", "BN_CONVERSATION", "BN_INLINE_TOAST_ALERT"}
|
||||
ChatFrame_RemoveAllMessageGroups(ChatFrame1)
|
||||
for _, v in ipairs(chatGroup) do
|
||||
ChatFrame_AddMessageGroup(ChatFrame1, v)
|
||||
end
|
||||
|
||||
chatGroup = {"COMBAT_XP_GAIN", "COMBAT_HONOR_GAIN", "COMBAT_FACTION_CHANGE", "SKILL", "LOOT", "MONEY"}
|
||||
ChatFrame_RemoveAllMessageGroups(ChatFrame3)
|
||||
for _, v in ipairs(chatGroup) do
|
||||
ChatFrame_AddMessageGroup(ChatFrame3, v)
|
||||
end
|
||||
|
||||
local chatGroup = {"GUILD", "OFFICER", "GUILD_ACHIEVEMENT"}
|
||||
ChatFrame_RemoveAllMessageGroups(ChatFrame4)
|
||||
for _, v in ipairs(chatGroup) do
|
||||
ChatFrame_AddMessageGroup(ChatFrame4, v)
|
||||
end
|
||||
|
||||
local chatGroup = {"WHISPER", "BN_WHISPER"}
|
||||
ChatFrame_RemoveAllMessageGroups(ChatFrame5)
|
||||
for _, v in ipairs(chatGroup) do
|
||||
ChatFrame_AddMessageGroup(ChatFrame5, v)
|
||||
end
|
||||
|
||||
ChatFrame_AddChannel(ChatFrame1, GENERAL)
|
||||
ChatFrame_RemoveChannel(ChatFrame1, TRADE)
|
||||
ChatFrame_RemoveChannel(ChatFrame1, "Ascension")
|
||||
ChatFrame_RemoveChannel(ChatFrame1, "World")
|
||||
ChatFrame_AddChannel(ChatFrame3, TRADE)
|
||||
ChatFrame_AddChannel(ChatFrame3, "Ascension")
|
||||
ChatFrame_AddChannel(ChatFrame3, "World")
|
||||
|
||||
chatGroup = {"SAY", "EMOTE", "YELL", "WHISPER", "PARTY", "PARTY_LEADER", "RAID", "RAID_LEADER", "RAID_WARNING", "BATTLEGROUND", "BATTLEGROUND_LEADER", "GUILD", "OFFICER", "ACHIEVEMENT", "GUILD_ACHIEVEMENT"}
|
||||
for i = 1, MAX_WOW_CHAT_CHANNELS do
|
||||
tinsert(chatGroup, "CHANNEL"..i)
|
||||
end
|
||||
for _, v in ipairs(chatGroup) do
|
||||
ToggleChatColorNamesByClassGroup(true, v)
|
||||
end
|
||||
|
||||
-- Create a list of replacement colors
|
||||
local replacementColors = {
|
||||
["General"] = {195/255, 230/255, 232/255},
|
||||
["Trade"] = {232/255, 158/255, 121/255},
|
||||
["LocalDefense"] = {232/255, 228/255, 121/255},
|
||||
["GuildRecruitment"] = {64/255, 255/255, 64/255},
|
||||
["LookingForGroup"] = {0/255, 206/255, 255/255},
|
||||
["Ascension"] = {255/255, 248/255, 163/255},
|
||||
["World"] = {255/255, 248/255, 163/255},
|
||||
}
|
||||
|
||||
-- Itterate through the channel list, and set the colors for each specific channel
|
||||
-- We need to do this because the channels change around so much
|
||||
-- low level characters start off with channel 1 being Ascension
|
||||
local chanList = { GetChannelList() }
|
||||
for i=1, #chanList, 2 do
|
||||
if replacementColors[chanList[i+1]] ~= nil then
|
||||
ChangeChatColor("CHANNEL"..chanList[i], unpack(replacementColors[chanList[i+1]]))
|
||||
end
|
||||
if chanList[i+1] == "GuildRecruitment" then
|
||||
ChatFrame_AddChannel(ChatFrame1, "GuildRecruitment")
|
||||
end
|
||||
end
|
||||
|
||||
if E.Chat then
|
||||
E.Chat:PositionChat(true)
|
||||
if E.db.RightChatPanelFaded then
|
||||
RightChatToggleButton:Click()
|
||||
end
|
||||
|
||||
if E.db.LeftChatPanelFaded then
|
||||
LeftChatToggleButton:Click()
|
||||
end
|
||||
end
|
||||
|
||||
if InstallStepComplete and not noDisplayMsg then
|
||||
InstallStepComplete.message = L["Chat Set"]
|
||||
InstallStepComplete:Show()
|
||||
end
|
||||
end
|
||||
|
||||
local function SetupCVars(noDisplayMsg)
|
||||
SetCVar("mapQuestDifficulty", 1)
|
||||
SetCVar("ShowClassColorInNameplate", 1)
|
||||
SetCVar("screenshotQuality", 10)
|
||||
SetCVar("chatMouseScroll", 1)
|
||||
SetCVar("chatStyle", "classic")
|
||||
SetCVar("WholeChatWindowClickable", 0)
|
||||
SetCVar("ConversationMode", "inline")
|
||||
SetCVar("showTutorials", 0)
|
||||
SetCVar("showNewbieTips", 0)
|
||||
SetCVar("showLootSpam", 1)
|
||||
SetCVar("UberTooltips", 1)
|
||||
SetCVar("threatWarning", 3)
|
||||
SetCVar("alwaysShowActionBars", 1)
|
||||
SetCVar("lockActionBars", 1)
|
||||
SetCVar("SpamFilter", 0)
|
||||
|
||||
if InstallStepComplete and not noDisplayMsg then
|
||||
InstallStepComplete.message = L["CVars Set"]
|
||||
InstallStepComplete:Show()
|
||||
end
|
||||
end
|
||||
|
||||
function E:GetColor(r, g, b, a)
|
||||
return {r = r, g = g, b = b, a = a}
|
||||
end
|
||||
|
||||
function E:SetupTheme(theme, noDisplayMsg)
|
||||
E.private.theme = theme
|
||||
|
||||
local classColor
|
||||
|
||||
--Set colors
|
||||
if theme == "classic" then
|
||||
E.db.general.bordercolor = (E.PixelMode and E:GetColor(0, 0, 0) or E:GetColor(0.31, 0.31, 0.31))
|
||||
E.db.general.backdropcolor = E:GetColor(0.1, 0.1, 0.1)
|
||||
E.db.general.backdropfadecolor = E:GetColor(13/255, 13/255, 13/255, 0.69)
|
||||
E.db.unitframe.colors.borderColor = (E.PixelMode and E:GetColor(0, 0, 0) or E:GetColor(0.31, 0.31, 0.31))
|
||||
E.db.unitframe.colors.healthclass = false
|
||||
E.db.unitframe.colors.health = E:GetColor(0.31, 0.31, 0.31)
|
||||
E.db.unitframe.colors.auraBarBuff = E:GetColor(0.31, 0.31, 0.31)
|
||||
E.db.unitframe.colors.castColor = E:GetColor(0.31, 0.31, 0.31)
|
||||
E.db.unitframe.colors.castClassColor = false
|
||||
elseif theme == "class" then
|
||||
classColor = E.media.herocolor
|
||||
|
||||
E.db.general.bordercolor = (E.PixelMode and E:GetColor(0, 0, 0) or E:GetColor(0.31, 0.31, 0.31))
|
||||
E.db.general.backdropcolor = E:GetColor(0.1, 0.1, 0.1)
|
||||
E.db.general.backdropfadecolor = E:GetColor(0.06, 0.06, 0.06, 0.8)
|
||||
E.db.unitframe.colors.borderColor = (E.PixelMode and E:GetColor(0, 0, 0) or E:GetColor(0.31, 0.31, 0.31))
|
||||
E.db.unitframe.colors.auraBarBuff = E:GetColor(classColor.r, classColor.g, classColor.b)
|
||||
E.db.unitframe.colors.healthclass = true
|
||||
E.db.unitframe.colors.castClassColor = true
|
||||
else
|
||||
E.db.general.bordercolor = (E.PixelMode and E:GetColor(0, 0, 0) or E:GetColor(0.1, 0.1, 0.1))
|
||||
E.db.general.backdropcolor = E:GetColor(0.1, 0.1, 0.1)
|
||||
E.db.general.backdropfadecolor = E:GetColor(0.054, 0.054, 0.054, 0.8)
|
||||
E.db.unitframe.colors.borderColor = (E.PixelMode and E:GetColor(0, 0, 0) or E:GetColor(0.1, 0.1, 0.1))
|
||||
E.db.unitframe.colors.auraBarBuff = E:GetColor(0.1, 0.1, 0.1)
|
||||
E.db.unitframe.colors.healthclass = false
|
||||
E.db.unitframe.colors.health = E:GetColor(0.1, 0.1, 0.1)
|
||||
E.db.unitframe.colors.castColor = E:GetColor(0.1, 0.1, 0.1)
|
||||
E.db.unitframe.colors.castClassColor = false
|
||||
end
|
||||
|
||||
--Value Color
|
||||
if theme == "class" then
|
||||
E.db.general.valuecolor = E:GetColor(classColor.r, classColor.g, classColor.b)
|
||||
else
|
||||
E.db.general.valuecolor = E:GetColor(254/255, 123/255, 44/255)
|
||||
end
|
||||
|
||||
E:UpdateAll(true)
|
||||
|
||||
if InstallStepComplete and not noDisplayMsg then
|
||||
InstallStepComplete.message = L["Theme Set"]
|
||||
InstallStepComplete:Show()
|
||||
end
|
||||
end
|
||||
|
||||
function E:SetupLayout(layout, noDataReset, noDisplayMsg)
|
||||
if not noDataReset then
|
||||
E.db.layoutSet = layout
|
||||
|
||||
--Unitframes
|
||||
E:CopyTable(E.db.unitframe.units, P.unitframe.units)
|
||||
|
||||
--Shared base layout, tweaks to individual layouts will be below
|
||||
E:ResetMovers("")
|
||||
if not E.db.movers then E.db.movers = {} end
|
||||
|
||||
--ActionBars
|
||||
E.db.actionbar.backdropSpacingConverted = true
|
||||
E.db.actionbar.bar1.buttons = 8
|
||||
E.db.actionbar.bar1.buttonsize = 50
|
||||
E.db.actionbar.bar1.buttonspacing = 1
|
||||
E.db.actionbar.bar2.buttons = 9
|
||||
E.db.actionbar.bar2.buttonsize = 38
|
||||
E.db.actionbar.bar2.buttonspacing = 1
|
||||
E.db.actionbar.bar2.enabled = true
|
||||
E.db.actionbar.bar2.visibility = "[vehicleui] hide; show"
|
||||
E.db.actionbar.bar3.buttons = 8
|
||||
E.db.actionbar.bar3.buttonsize = 50
|
||||
E.db.actionbar.bar3.buttonspacing = 1
|
||||
E.db.actionbar.bar3.buttonsPerRow = 10
|
||||
E.db.actionbar.bar3.visibility = "[vehicleui] hide; show"
|
||||
E.db.actionbar.bar4.enabled = false
|
||||
E.db.actionbar.bar4.visibility = "[vehicleui] hide; show"
|
||||
E.db.actionbar.bar5.enabled = false
|
||||
E.db.actionbar.bar5.visibility = "[vehicleui] hide; show"
|
||||
E.db.actionbar.bar6.visibility = "[vehicleui] hide; show"
|
||||
--Auras
|
||||
E.db.auras.buffs.countFontSize = 10
|
||||
E.db.auras.buffs.size = 40
|
||||
E.db.auras.debuffs.countFontSize = 10
|
||||
E.db.auras.debuffs.size = 40
|
||||
--Bags
|
||||
E.db.bags.bagSize = 42
|
||||
E.db.bags.bagWidth = 472
|
||||
E.db.bags.bankSize = 42
|
||||
E.db.bags.bankWidth = 472
|
||||
--Chat
|
||||
E.db.chat.fontSize = 10
|
||||
E.db.chat.panelColorConverted = true
|
||||
E.db.chat.separateSizes = false
|
||||
E.db.chat.panelHeight = 236
|
||||
E.db.chat.panelWidth = 472
|
||||
E.db.chat.tapFontSize = 10
|
||||
--DataBars
|
||||
E.db.databars.experience.height = 10
|
||||
E.db.databars.experience.orientation = "HORIZONTAL"
|
||||
E.db.databars.experience.textSize = 12
|
||||
E.db.databars.experience.width = 350
|
||||
E.db.databars.reputation.enable = true
|
||||
E.db.databars.reputation.height = 10
|
||||
E.db.databars.reputation.orientation = "HORIZONTAL"
|
||||
E.db.databars.reputation.width = 222
|
||||
--General
|
||||
E.db.general.minimap.size = 220
|
||||
E.db.general.watchFrameHeight = 400
|
||||
E.db.general.totems.growthDirection = "HORIZONTAL"
|
||||
E.db.general.totems.size = 50
|
||||
E.db.general.totems.spacing = 8
|
||||
E.db.general.reminder.enable = false
|
||||
--Movers
|
||||
E.db.movers.AlertFrameMover = "TOP,ElvUIParent,TOP,-1,-18"
|
||||
E.db.movers.BNETMover = "TOPRIGHT,ElvUIParent,TOPRIGHT,-4,-274"
|
||||
E.db.movers.ElvAB_1 = "BOTTOM,ElvUIParent,BOTTOM,0,190"
|
||||
E.db.movers.ElvAB_2 = "BOTTOM,ElvUIParent,BOTTOM,0,4"
|
||||
E.db.movers.ElvAB_3 = "BOTTOM,ElvUIParent,BOTTOM,0,138"
|
||||
E.db.movers.ElvAB_5 = "BOTTOM,ElvUIParent,BOTTOM,-92,57"
|
||||
E.db.movers.ElvBar_Totem = "BOTTOM,ElvUIParent,BOTTOM,0,55"
|
||||
E.db.movers.ElvUF_FocusMover = "BOTTOM,ElvUIParent,BOTTOM,342,59"
|
||||
E.db.movers.ElvUF_PartyMover = "BOTTOMLEFT,ElvUIParent,BOTTOMLEFT,4,248"
|
||||
E.db.movers.ElvUF_PetMover = "BOTTOM,ElvUIParent,BOTTOM,-341,99"
|
||||
E.db.movers.ElvUF_PlayerCastbarMover = "BOTTOM,ElvUIParent,BOTTOM,0,96"
|
||||
E.db.movers.ElvUF_PlayerMover = "BOTTOM,ElvUIParent,BOTTOM,-341,138"
|
||||
E.db.movers.ElvUF_Raid40Mover = "TOPLEFT,ElvUIParent,BOTTOMLEFT,4,482"
|
||||
E.db.movers.ElvUF_RaidMover = "BOTTOMLEFT,ElvUIParent,BOTTOMLEFT,4,248"
|
||||
E.db.movers.ElvUF_RaidpetMover = "TOPLEFT,ElvUIParent,BOTTOMLEFT,4,737"
|
||||
E.db.movers.ElvUF_TargetCastbarMover = "BOTTOM,ElvUIParent,BOTTOM,0,242"
|
||||
E.db.movers.ElvUF_TargetMover = "BOTTOM,ElvUIParent,BOTTOM,342,138"
|
||||
E.db.movers.ElvUF_TargetTargetMover = "BOTTOM,ElvUIParent,BOTTOM,342,99"
|
||||
E.db.movers.ExperienceBarMover = "BOTTOM,ElvUIParent,BOTTOM,0,43"
|
||||
E.db.movers.LootFrameMover = "TOPLEFT,ElvUIParent,TOPLEFT,418,-186"
|
||||
E.db.movers.MirrorTimer1Mover = "TOP,ElvUIParent,TOP,-1,-96"
|
||||
E.db.movers.WatchFrameMover = "TOPRIGHT,ElvUIParent,TOPRIGHT,-163,-325"
|
||||
E.db.movers.ReputationBarMover = "TOPRIGHT,ElvUIParent,TOPRIGHT,-2,-245"
|
||||
E.db.movers.ShiftAB = "TOPLEFT,ElvUIParent,BOTTOMLEFT,4,769"
|
||||
E.db.movers.TempEnchantMover = "TOPRIGHT,ElvUIParent,TOPRIGHT,-4,-257"
|
||||
E.db.movers.TotemBarMover = "BOTTOMLEFT,ElvUIParent,BOTTOMLEFT,485,4"
|
||||
E.db.movers.VehicleSeatMover = "TOPLEFT,ElvUIParent,TOPLEFT,4,-4"
|
||||
--Tooltip
|
||||
E.db.tooltip.fontSize = 10
|
||||
E.db.tooltip.healthBar.fontOutline = "MONOCHROMEOUTLINE"
|
||||
E.db.tooltip.healthBar.height = 12
|
||||
--UnitFrames
|
||||
E.db.unitframe.smoothbars = true
|
||||
E.db.unitframe.thinBorders = true
|
||||
--Player
|
||||
E.db.unitframe.units.player.aurabar.height = 26
|
||||
E.db.unitframe.units.player.buffs.perrow = 7
|
||||
E.db.unitframe.units.player.castbar.height = 40
|
||||
E.db.unitframe.units.player.castbar.insideInfoPanel = false
|
||||
E.db.unitframe.units.player.castbar.width = 407
|
||||
E.db.unitframe.units.player.classbar.height = 14
|
||||
E.db.unitframe.units.player.debuffs.perrow = 7
|
||||
E.db.unitframe.units.player.disableMouseoverGlow = true
|
||||
E.db.unitframe.units.player.health.attachTextTo = "InfoPanel"
|
||||
E.db.unitframe.units.player.height = 82
|
||||
E.db.unitframe.units.player.infoPanel.enable = true
|
||||
E.db.unitframe.units.player.power.attachTextTo = "InfoPanel"
|
||||
E.db.unitframe.units.player.power.height = 22
|
||||
--Target
|
||||
E.db.unitframe.units.target.aurabar.height = 26
|
||||
E.db.unitframe.units.target.buffs.anchorPoint = "TOPLEFT"
|
||||
E.db.unitframe.units.target.buffs.perrow = 7
|
||||
E.db.unitframe.units.target.castbar.height = 40
|
||||
E.db.unitframe.units.target.castbar.insideInfoPanel = false
|
||||
E.db.unitframe.units.target.castbar.width = 407
|
||||
E.db.unitframe.units.target.debuffs.anchorPoint = "TOPLEFT"
|
||||
E.db.unitframe.units.target.debuffs.attachTo = "FRAME"
|
||||
E.db.unitframe.units.target.debuffs.enable = false
|
||||
E.db.unitframe.units.target.debuffs.maxDuration = 0
|
||||
E.db.unitframe.units.target.debuffs.perrow = 7
|
||||
E.db.unitframe.units.target.disableMouseoverGlow = true
|
||||
E.db.unitframe.units.target.health.attachTextTo = "InfoPanel"
|
||||
E.db.unitframe.units.target.height = 82
|
||||
E.db.unitframe.units.target.infoPanel.enable = true
|
||||
E.db.unitframe.units.target.name.attachTextTo = "InfoPanel"
|
||||
E.db.unitframe.units.target.name.text_format = "[namecolor][name]"
|
||||
E.db.unitframe.units.target.orientation = "LEFT"
|
||||
E.db.unitframe.units.target.power.attachTextTo = "InfoPanel"
|
||||
E.db.unitframe.units.target.power.height = 22
|
||||
--TargetTarget
|
||||
E.db.unitframe.units.targettarget.debuffs.anchorPoint = "TOPRIGHT"
|
||||
E.db.unitframe.units.targettarget.debuffs.enable = false
|
||||
E.db.unitframe.units.targettarget.disableMouseoverGlow = true
|
||||
E.db.unitframe.units.targettarget.power.enable = false
|
||||
E.db.unitframe.units.targettarget.raidicon.attachTo = "LEFT"
|
||||
E.db.unitframe.units.targettarget.raidicon.enable = false
|
||||
E.db.unitframe.units.targettarget.raidicon.xOffset = 2
|
||||
E.db.unitframe.units.targettarget.raidicon.yOffset = 0
|
||||
E.db.unitframe.units.targettarget.threatStyle = "GLOW"
|
||||
E.db.unitframe.units.targettarget.width = 270
|
||||
--Focus
|
||||
E.db.unitframe.units.focus.castbar.width = 270
|
||||
E.db.unitframe.units.focus.width = 270
|
||||
--Pet
|
||||
E.db.unitframe.units.pet.castbar.iconSize = 32
|
||||
E.db.unitframe.units.pet.castbar.width = 270
|
||||
E.db.unitframe.units.pet.debuffs.anchorPoint = "TOPRIGHT"
|
||||
E.db.unitframe.units.pet.debuffs.enable = true
|
||||
E.db.unitframe.units.pet.disableTargetGlow = false
|
||||
E.db.unitframe.units.pet.infoPanel.height = 14
|
||||
E.db.unitframe.units.pet.portrait.camDistanceScale = 2
|
||||
E.db.unitframe.units.pet.width = 270
|
||||
--Boss
|
||||
E.db.unitframe.units.boss.buffs.maxDuration = 300
|
||||
E.db.unitframe.units.boss.buffs.sizeOverride = 27
|
||||
E.db.unitframe.units.boss.buffs.yOffset = 16
|
||||
E.db.unitframe.units.boss.castbar.width = 246
|
||||
E.db.unitframe.units.boss.debuffs.maxDuration = 300
|
||||
E.db.unitframe.units.boss.debuffs.numrows = 1
|
||||
E.db.unitframe.units.boss.debuffs.sizeOverride = 27
|
||||
E.db.unitframe.units.boss.debuffs.yOffset = -16
|
||||
E.db.unitframe.units.boss.height = 60
|
||||
E.db.unitframe.units.boss.infoPanel.height = 17
|
||||
E.db.unitframe.units.boss.portrait.camDistanceScale = 2
|
||||
E.db.unitframe.units.boss.portrait.width = 45
|
||||
E.db.unitframe.units.boss.width = 246
|
||||
--Party
|
||||
E.db.unitframe.units.party.height = 74
|
||||
E.db.unitframe.units.party.power.height = 13
|
||||
E.db.unitframe.units.party.rdebuffs.font = "PT Sans Narrow"
|
||||
E.db.unitframe.units.party.width = 231
|
||||
--Raid
|
||||
E.db.unitframe.units.raid.growthDirection = "RIGHT_UP"
|
||||
E.db.unitframe.units.raid.health.frequentUpdates = true
|
||||
E.db.unitframe.units.raid.infoPanel.enable = true
|
||||
E.db.unitframe.units.raid.name.attachTextTo = "InfoPanel"
|
||||
E.db.unitframe.units.raid.name.position = "BOTTOMLEFT"
|
||||
E.db.unitframe.units.raid.name.xOffset = 2
|
||||
E.db.unitframe.units.raid.numGroups = 8
|
||||
E.db.unitframe.units.raid.rdebuffs.font = "PT Sans Narrow"
|
||||
E.db.unitframe.units.raid.rdebuffs.size = 30
|
||||
E.db.unitframe.units.raid.rdebuffs.xOffset = 30
|
||||
E.db.unitframe.units.raid.rdebuffs.yOffset = 25
|
||||
E.db.unitframe.units.raid.resurrectIcon.attachTo = "BOTTOMRIGHT"
|
||||
E.db.unitframe.units.raid.visibility = "[@raid6,noexists] hide;show"
|
||||
E.db.unitframe.units.raid.width = 92
|
||||
--Raid40
|
||||
E.db.unitframe.units.raid40.enable = false
|
||||
E.db.unitframe.units.raid40.rdebuffs.font = "PT Sans Narrow"
|
||||
|
||||
--[[
|
||||
-- Layout Tweaks will be handled below.
|
||||
-- These are changes that deviate from the shared base layout
|
||||
--]]
|
||||
|
||||
if layout == "dpsCaster" then
|
||||
E.db.movers.ElvUF_PlayerCastbarMover = "BOTTOM,ElvUIParent,BOTTOM,0,243"
|
||||
E.db.movers.ElvUF_TargetCastbarMover = "BOTTOM,ElvUIParent,BOTTOM,0,97"
|
||||
elseif layout == "healer" then
|
||||
E.db.movers.ElvUF_PlayerCastbarMover = "BOTTOM,ElvUIParent,BOTTOM,0,243"
|
||||
E.db.movers.ElvUF_TargetCastbarMover = "BOTTOM,ElvUIParent,BOTTOM,0,97"
|
||||
E.db.movers.ElvUF_RaidMover = "BOTTOMLEFT,ElvUIParent,BOTTOMLEFT,202,373"
|
||||
E.db.movers.LootFrameMover = "TOPLEFT,ElvUIParent,TOPLEFT,250,-104"
|
||||
E.db.movers.ShiftAB = "TOPLEFT,ElvUIParent,BOTTOMLEFT,4,273"
|
||||
E.db.unitframe.units.party.enable = false
|
||||
E.db.unitframe.units.party.health.frequentUpdates = true
|
||||
E.db.unitframe.units.raid.visibility = "[nogroup] hide;show"
|
||||
E.db.unitframe.units.raid40.health.frequentUpdates = true
|
||||
end
|
||||
end
|
||||
|
||||
E:UpdateAll(true)
|
||||
|
||||
if InstallStepComplete and not noDisplayMsg then
|
||||
InstallStepComplete.message = L["Layout Set"]
|
||||
InstallStepComplete:Show()
|
||||
end
|
||||
end
|
||||
|
||||
local function SetupAuras(style, noDisplayMsg)
|
||||
local frame = UF.player
|
||||
E:CopyTable(E.db.unitframe.units.player.buffs, P.unitframe.units.player.buffs)
|
||||
E:CopyTable(E.db.unitframe.units.player.debuffs, P.unitframe.units.player.debuffs)
|
||||
E:CopyTable(E.db.unitframe.units.player.aurabar, P.unitframe.units.player.aurabar)
|
||||
if frame then
|
||||
UF:Configure_Auras(frame, "Buffs")
|
||||
UF:Configure_Auras(frame, "Debuffs")
|
||||
UF:Configure_AuraBars(frame)
|
||||
end
|
||||
|
||||
frame = UF.target
|
||||
E:CopyTable(E.db.unitframe.units.target.buffs, P.unitframe.units.target.buffs)
|
||||
E:CopyTable(E.db.unitframe.units.target.debuffs, P.unitframe.units.target.debuffs)
|
||||
E:CopyTable(E.db.unitframe.units.target.aurabar, P.unitframe.units.target.aurabar)
|
||||
if frame then
|
||||
UF:Configure_Auras(frame, "Buffs")
|
||||
UF:Configure_Auras(frame, "Debuffs")
|
||||
UF:Configure_AuraBars(frame)
|
||||
end
|
||||
|
||||
frame = UF.focus
|
||||
E:CopyTable(E.db.unitframe.units.focus.buffs, P.unitframe.units.focus.buffs)
|
||||
E:CopyTable(E.db.unitframe.units.focus.debuffs, P.unitframe.units.focus.debuffs)
|
||||
E:CopyTable(E.db.unitframe.units.focus.aurabar, P.unitframe.units.focus.aurabar)
|
||||
if frame then
|
||||
UF:Configure_Auras(frame, "Buffs")
|
||||
UF:Configure_Auras(frame, "Debuffs")
|
||||
UF:Configure_AuraBars(frame)
|
||||
end
|
||||
|
||||
if not style then
|
||||
--PLAYER
|
||||
E.db.unitframe.units.player.buffs.enable = true
|
||||
E.db.unitframe.units.player.buffs.attachTo = "FRAME"
|
||||
E.db.unitframe.units.player.debuffs.attachTo = "BUFFS"
|
||||
E.db.unitframe.units.player.aurabar.enable = false
|
||||
if E.private.unitframe.enable then
|
||||
UF:CreateAndUpdateUF("player")
|
||||
end
|
||||
|
||||
--TARGET
|
||||
E.db.unitframe.units.target.debuffs.enable = true
|
||||
E.db.unitframe.units.target.aurabar.enable = false
|
||||
if E.private.unitframe.enable then
|
||||
UF:CreateAndUpdateUF("target")
|
||||
end
|
||||
end
|
||||
|
||||
if InstallStepComplete and not noDisplayMsg then
|
||||
InstallStepComplete.message = L["Auras Set"]
|
||||
InstallStepComplete:Show()
|
||||
end
|
||||
end
|
||||
|
||||
local function InstallComplete()
|
||||
E.private.install_complete = E.version
|
||||
|
||||
ReloadUI()
|
||||
end
|
||||
|
||||
local function ResetAll()
|
||||
InstallNextButton:Disable()
|
||||
InstallPrevButton:Disable()
|
||||
InstallOption1Button:Hide()
|
||||
InstallOption1Button:SetScript("OnClick", nil)
|
||||
InstallOption1Button:SetText("")
|
||||
InstallOption2Button:Hide()
|
||||
InstallOption2Button:SetScript("OnClick", nil)
|
||||
InstallOption2Button:SetText("")
|
||||
InstallOption3Button:Hide()
|
||||
InstallOption3Button:SetScript("OnClick", nil)
|
||||
InstallOption3Button:SetText("")
|
||||
InstallOption4Button:Hide()
|
||||
InstallOption4Button:SetScript("OnClick", nil)
|
||||
InstallOption4Button:SetText("")
|
||||
InstallSlider:Hide()
|
||||
InstallSlider.Min:SetText("")
|
||||
InstallSlider.Max:SetText("")
|
||||
InstallSlider.Cur:SetText("")
|
||||
ElvUIInstallFrame.SubTitle:SetText("")
|
||||
ElvUIInstallFrame.Desc1:SetText("")
|
||||
ElvUIInstallFrame.Desc2:SetText("")
|
||||
ElvUIInstallFrame.Desc3:SetText("")
|
||||
ElvUIInstallFrame:Size(550, 400)
|
||||
end
|
||||
|
||||
local function SetPage(PageNum)
|
||||
CURRENT_PAGE = PageNum
|
||||
ResetAll()
|
||||
|
||||
InstallStatus.anim.progress:SetChange(PageNum)
|
||||
InstallStatus.anim.progress:Play()
|
||||
InstallStatus.text:SetText(CURRENT_PAGE.." / "..MAX_PAGE)
|
||||
|
||||
local r, g, b = E:ColorGradient(CURRENT_PAGE / MAX_PAGE, 1, 0, 0, 1, 1, 0, 0, 1, 0)
|
||||
ElvUIInstallFrame.Status:SetStatusBarColor(r, g, b)
|
||||
|
||||
if PageNum == MAX_PAGE then
|
||||
InstallNextButton:Disable()
|
||||
else
|
||||
InstallNextButton:Enable()
|
||||
end
|
||||
|
||||
if PageNum == 1 then
|
||||
InstallPrevButton:Disable()
|
||||
else
|
||||
InstallPrevButton:Enable()
|
||||
end
|
||||
|
||||
local f = ElvUIInstallFrame
|
||||
if PageNum == 1 then
|
||||
f.SubTitle:SetFormattedText(L["Welcome to ElvUI version %s!"], E.version)
|
||||
f.Desc1:SetText(L["This install process will help you learn some of the features in ElvUI has to offer and also prepare your user interface for usage."])
|
||||
f.Desc2:SetText(L["The in-game configuration menu can be accessed by typing the /ec command or by clicking the 'C' button on the minimap. Press the button below if you wish to skip the installation process."])
|
||||
f.Desc3:SetText(L["Please press the continue button to go onto the next step."])
|
||||
InstallOption1Button:Show()
|
||||
InstallOption1Button:SetScript("OnClick", InstallComplete)
|
||||
InstallOption1Button:SetText(L["Skip Process"])
|
||||
elseif PageNum == 2 then
|
||||
f.SubTitle:SetText(L["CVars"])
|
||||
f.Desc1:SetText(L["This part of the installation process sets up your World of Warcraft default options it is recommended you should do this step for everything to behave properly."])
|
||||
f.Desc2:SetText(L["Please click the button below to setup your CVars."])
|
||||
f.Desc3:SetText(L["Importance: |cff07D400High|r"])
|
||||
InstallOption1Button:Show()
|
||||
InstallOption1Button:SetScript("OnClick", function() SetupCVars() end)
|
||||
InstallOption1Button:SetText(L["Setup CVars"])
|
||||
elseif PageNum == 3 then
|
||||
f.SubTitle:SetText(L["Chat"])
|
||||
f.Desc1:SetText(L["This part of the installation process sets up your chat windows names, positions and colors."])
|
||||
f.Desc2:SetText(L["The chat windows function the same as Blizzard standard chat windows, you can right click the tabs and drag them around, rename, etc. Please click the button below to setup your chat windows."])
|
||||
f.Desc3:SetText(L["Importance: |cffD3CF00Medium|r"])
|
||||
InstallOption1Button:Show()
|
||||
InstallOption1Button:SetScript("OnClick", function() SetupChat() end)
|
||||
InstallOption1Button:SetText(L["Setup Chat"])
|
||||
elseif PageNum == 4 then
|
||||
f.SubTitle:SetText(L["Theme Setup"])
|
||||
f.Desc1:SetText(L["Choose a theme layout you wish to use for your initial setup."])
|
||||
f.Desc2:SetText(L["You can always change fonts and colors of any element of ElvUI from the in-game configuration."])
|
||||
f.Desc3:SetText(L["Importance: |cffFF0000Low|r"])
|
||||
InstallOption1Button:Show()
|
||||
InstallOption1Button:SetScript("OnClick", function() E:SetupTheme("classic") end)
|
||||
InstallOption1Button:SetText(L["Classic"])
|
||||
InstallOption2Button:Show()
|
||||
InstallOption2Button:SetScript("OnClick", function() E:SetupTheme("default") end)
|
||||
InstallOption2Button:SetText(L["Dark"])
|
||||
InstallOption3Button:Show()
|
||||
InstallOption3Button:SetScript("OnClick", function() E:SetupTheme("class") end)
|
||||
InstallOption3Button:SetText(CLASS)
|
||||
elseif PageNum == 5 then
|
||||
f.SubTitle:SetText(L["UI Scale"])
|
||||
f.Desc1:SetFormattedText(L["Adjust the UI Scale to fit your screen, press the autoscale button to set the UI Scale automatically."])
|
||||
InstallSlider:Show()
|
||||
InstallSlider:SetValueStep(0.01)
|
||||
InstallSlider:SetMinMaxValues(0.4, 1.15)
|
||||
|
||||
local value = E.global.general.UIScale
|
||||
InstallSlider:SetValue(value)
|
||||
InstallSlider.Cur:SetText(value)
|
||||
InstallSlider:SetScript("OnValueChanged", function(self)
|
||||
E.global.general.UIScale = self:GetValue()
|
||||
InstallSlider.Cur:SetText(E.global.general.UIScale)
|
||||
end)
|
||||
|
||||
InstallSlider.Min:SetText(0.4)
|
||||
InstallSlider.Max:SetText(1.15)
|
||||
InstallOption1Button:Show()
|
||||
InstallOption1Button:SetScript("OnClick", function()
|
||||
local scale = E:PixelBestSize()
|
||||
|
||||
-- this is to just keep the slider in place, the values need updated again afterwards
|
||||
InstallSlider:SetValue(scale)
|
||||
|
||||
-- update the values with deeper accuracy
|
||||
E.global.general.UIScale = scale
|
||||
InstallSlider.Cur:SetText(E.global.general.UIScale)
|
||||
end)
|
||||
|
||||
InstallOption1Button:SetText(L["Auto Scale"])
|
||||
InstallOption2Button:Show()
|
||||
InstallOption2Button:SetScript("OnClick", function()
|
||||
E:PixelScaleChanged(nil, true)
|
||||
end)
|
||||
|
||||
InstallOption2Button:SetText(L["Preview"])
|
||||
f.Desc3:SetText(L["Importance: |cff07D400High|r"])
|
||||
elseif PageNum == 6 then
|
||||
f.SubTitle:SetText(L["Layout"])
|
||||
f.Desc1:SetText(L["You can now choose what layout you wish to use based on your combat role."])
|
||||
f.Desc2:SetText(L["This will change the layout of your unitframes and actionbars."])
|
||||
f.Desc3:SetText(L["Importance: |cffD3CF00Medium|r"])
|
||||
InstallOption1Button:Show()
|
||||
InstallOption1Button:SetScript("OnClick", function() E.db.layoutSet = nil E:SetupLayout("tank") end)
|
||||
InstallOption1Button:SetText(L["Tank / Physical DPS"])
|
||||
InstallOption2Button:Show()
|
||||
InstallOption2Button:SetScript("OnClick", function() E.db.layoutSet = nil E:SetupLayout("healer") end)
|
||||
InstallOption2Button:SetText(L["Healer"])
|
||||
InstallOption3Button:Show()
|
||||
InstallOption3Button:SetScript("OnClick", function() E.db.layoutSet = nil E:SetupLayout("dpsCaster") end)
|
||||
InstallOption3Button:SetText(L["Caster DPS"])
|
||||
elseif PageNum == 7 then
|
||||
f.SubTitle:SetText(L["Auras"])
|
||||
f.Desc1:SetText(L["Select the type of aura system you want to use with ElvUI's unitframes. Set to Aura Bar & Icons to use both aura bars and icons, set to icons only to only see icons."])
|
||||
f.Desc2:SetText(L["If you have an icon or aurabar that you don't want to display simply hold down shift and right click the icon for it to disapear."])
|
||||
f.Desc3:SetText(L["Importance: |cffD3CF00Medium|r"])
|
||||
InstallOption1Button:Show()
|
||||
InstallOption1Button:SetScript("OnClick", function() SetupAuras(true) end)
|
||||
InstallOption1Button:SetText(L["Aura Bars & Icons"])
|
||||
InstallOption2Button:Show()
|
||||
InstallOption2Button:SetScript("OnClick", function() SetupAuras() end)
|
||||
InstallOption2Button:SetText(L["Icons Only"])
|
||||
elseif PageNum == 8 then
|
||||
f.SubTitle:SetText(L["Installation Complete"])
|
||||
f.Desc1:SetText(L["You are now finished with the installation process. If you are in need of technical support please visit us at https://github.com/ElvUI-WotLK."])
|
||||
f.Desc2:SetText(L["Please click the button below so you can setup variables and ReloadUI."])
|
||||
InstallOption1Button:Show()
|
||||
InstallOption1Button:SetScript("OnClick", function() E:StaticPopup_Show("ELVUI_EDITBOX", nil, nil, "https://discord.gg/UXSc7nt") end)
|
||||
InstallOption1Button:SetText(L["Discord"])
|
||||
InstallOption2Button:Show()
|
||||
InstallOption2Button:SetScript("OnClick", InstallComplete)
|
||||
InstallOption2Button:SetText(L["Finished"])
|
||||
ElvUIInstallFrame:Size(550, 350)
|
||||
end
|
||||
end
|
||||
|
||||
local function NextPage()
|
||||
if CURRENT_PAGE ~= MAX_PAGE then
|
||||
CURRENT_PAGE = CURRENT_PAGE + 1
|
||||
SetPage(CURRENT_PAGE)
|
||||
end
|
||||
end
|
||||
|
||||
local function PreviousPage()
|
||||
if CURRENT_PAGE ~= 1 then
|
||||
CURRENT_PAGE = CURRENT_PAGE - 1
|
||||
SetPage(CURRENT_PAGE)
|
||||
end
|
||||
end
|
||||
|
||||
--Install UI
|
||||
function E:Install()
|
||||
if not InstallStepComplete then
|
||||
local imsg = CreateFrame("Frame", "InstallStepComplete", E.UIParent)
|
||||
imsg:Size(418, 72)
|
||||
imsg:Point("TOP", 0, -190)
|
||||
imsg:Hide()
|
||||
imsg:SetScript("OnShow", function(f)
|
||||
if f.message then
|
||||
PlaySoundFile([[Sound\Interface\LevelUp.wav]])
|
||||
f.text:SetText(f.message)
|
||||
UIFrameFadeOut(f, 3.5, 1, 0)
|
||||
E:Delay(4, f.Hide, f)
|
||||
f.message = nil
|
||||
else
|
||||
f:Hide()
|
||||
end
|
||||
end)
|
||||
|
||||
imsg.firstShow = false
|
||||
|
||||
imsg.bg = imsg:CreateTexture(nil, "BACKGROUND")
|
||||
imsg.bg:SetTexture([[Interface\AddOns\ElvUI\media\textures\LevelUpTex]])
|
||||
imsg.bg:Point("BOTTOM")
|
||||
imsg.bg:Size(326, 103)
|
||||
imsg.bg:SetTexCoord(0.00195313, 0.63867188, 0.03710938, 0.23828125)
|
||||
imsg.bg:SetVertexColor(1, 1, 1, 0.6)
|
||||
|
||||
imsg.lineTop = imsg:CreateTexture(nil, "BACKGROUND")
|
||||
imsg.lineTop:SetDrawLayer("BACKGROUND")
|
||||
imsg.lineTop:SetTexture([[Interface\AddOns\ElvUI\media\textures\LevelUpTex]])
|
||||
imsg.lineTop:Point("TOP")
|
||||
imsg.lineTop:Size(418, 7)
|
||||
imsg.lineTop:SetTexCoord(0.00195313, 0.81835938, 0.01953125, 0.03320313)
|
||||
|
||||
imsg.lineBottom = imsg:CreateTexture(nil, "BACKGROUND")
|
||||
imsg.lineBottom:SetDrawLayer("BACKGROUND")
|
||||
imsg.lineBottom:SetTexture([[Interface\AddOns\ElvUI\media\textures\LevelUpTex]])
|
||||
imsg.lineBottom:Point("BOTTOM")
|
||||
imsg.lineBottom:Size(418, 7)
|
||||
imsg.lineBottom:SetTexCoord(0.00195313, 0.81835938, 0.01953125, 0.03320313)
|
||||
|
||||
imsg.text = imsg:CreateFontString(nil, "OVERLAY")
|
||||
imsg.text:FontTemplate(E.media.normFont, 32, "OUTLINE")
|
||||
imsg.text:Point("BOTTOM", 0, 16)
|
||||
imsg.text:SetTextColor(1, 0.82, 0)
|
||||
imsg.text:SetJustifyH("CENTER")
|
||||
end
|
||||
|
||||
--Create Frame
|
||||
if not ElvUIInstallFrame then
|
||||
local f = CreateFrame("Button", "ElvUIInstallFrame", E.UIParent)
|
||||
f.SetPage = SetPage
|
||||
f:Size(550, 400)
|
||||
f:SetTemplate("Transparent")
|
||||
f:Point("CENTER")
|
||||
f:SetFrameStrata("TOOLTIP")
|
||||
|
||||
f:SetMovable(true)
|
||||
f:EnableMouse(true)
|
||||
f:RegisterForDrag("LeftButton")
|
||||
f:SetScript("OnDragStart", function(frame) frame:StartMoving() frame:SetUserPlaced(false) end)
|
||||
f:SetScript("OnDragStop", function(frame) frame:StopMovingOrSizing() end)
|
||||
|
||||
f.Title = f:CreateFontString(nil, "OVERLAY")
|
||||
f.Title:FontTemplate(nil, 17, nil)
|
||||
f.Title:Point("TOP", 0, -5)
|
||||
f.Title:SetText(L["ElvUI Installation"])
|
||||
|
||||
f.Next = CreateFrame("Button", "InstallNextButton", f, "UIPanelButtonTemplate")
|
||||
f.Next:Size(110, 25)
|
||||
f.Next:Point("BOTTOMRIGHT", -5, 5)
|
||||
f.Next:SetText(CONTINUE)
|
||||
f.Next:Disable()
|
||||
f.Next:SetScript("OnClick", NextPage)
|
||||
S:HandleButton(f.Next, true)
|
||||
|
||||
f.Prev = CreateFrame("Button", "InstallPrevButton", f, "UIPanelButtonTemplate")
|
||||
f.Prev:Size(110, 25)
|
||||
f.Prev:Point("BOTTOMLEFT", 5, 5)
|
||||
f.Prev:SetText(PREVIOUS)
|
||||
f.Prev:Disable()
|
||||
f.Prev:SetScript("OnClick", PreviousPage)
|
||||
S:HandleButton(f.Prev, true)
|
||||
|
||||
f.Status = CreateFrame("StatusBar", "InstallStatus", f)
|
||||
f.Status:SetFrameLevel(f.Status:GetFrameLevel() + 2)
|
||||
f.Status:CreateBackdrop()
|
||||
f.Status:SetStatusBarTexture(E.media.normTex)
|
||||
E:RegisterStatusBar(f.Status)
|
||||
f.Status:SetMinMaxValues(0, MAX_PAGE)
|
||||
f.Status:Point("TOPLEFT", f.Prev, "TOPRIGHT", 6, -2)
|
||||
f.Status:Point("BOTTOMRIGHT", f.Next, "BOTTOMLEFT", -6, 2)
|
||||
|
||||
-- Setup StatusBar Animation
|
||||
f.Status.anim = CreateAnimationGroup(f.Status)
|
||||
f.Status.anim.progress = f.Status.anim:CreateAnimation("Progress")
|
||||
f.Status.anim.progress:SetEasing("Out")
|
||||
f.Status.anim.progress:SetDuration(0.3)
|
||||
|
||||
f.Status.text = f.Status:CreateFontString(nil, "OVERLAY")
|
||||
f.Status.text:FontTemplate()
|
||||
f.Status.text:Point("CENTER")
|
||||
f.Status.text:SetText(CURRENT_PAGE.." / "..MAX_PAGE)
|
||||
|
||||
f.Slider = CreateFrame("Slider", "InstallSlider", f)
|
||||
f.Slider:SetOrientation("HORIZONTAL")
|
||||
f.Slider:Height(15)
|
||||
f.Slider:Width(400)
|
||||
f.Slider:SetHitRectInsets(0, 0, -10, 0)
|
||||
f.Slider:SetPoint("CENTER", 0, 45)
|
||||
S:HandleSliderFrame(f.Slider)
|
||||
f.Slider:Hide()
|
||||
|
||||
f.Slider.Min = f.Slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
|
||||
f.Slider.Min:SetPoint("RIGHT", f.Slider, "LEFT", -3, 0)
|
||||
f.Slider.Max = f.Slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
|
||||
f.Slider.Max:SetPoint("LEFT", f.Slider, "RIGHT", 3, 0)
|
||||
f.Slider.Cur = f.Slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
|
||||
f.Slider.Cur:SetPoint("BOTTOM", f.Slider, "TOP", 0, 10)
|
||||
f.Slider.Cur:FontTemplate(nil, 30, nil)
|
||||
|
||||
f.Option1 = CreateFrame("Button", "InstallOption1Button", f, "UIPanelButtonTemplate")
|
||||
f.Option1:Size(160, 30)
|
||||
f.Option1:Point("BOTTOM", 0, 45)
|
||||
f.Option1:SetText("")
|
||||
f.Option1:Hide()
|
||||
S:HandleButton(f.Option1, true)
|
||||
|
||||
f.Option2 = CreateFrame("Button", "InstallOption2Button", f, "UIPanelButtonTemplate")
|
||||
f.Option2:Size(110, 30)
|
||||
f.Option2:Point("BOTTOMLEFT", f, "BOTTOM", 4, 45)
|
||||
f.Option2:SetText("")
|
||||
f.Option2:Hide()
|
||||
f.Option2:SetScript("OnShow", function()
|
||||
f.Option1:Width(110)
|
||||
f.Option1:ClearAllPoints()
|
||||
f.Option1:Point("BOTTOMRIGHT", f, "BOTTOM", -4, 45)
|
||||
end)
|
||||
f.Option2:SetScript("OnHide", function()
|
||||
f.Option1:Width(160)
|
||||
f.Option1:ClearAllPoints()
|
||||
f.Option1:Point("BOTTOM", 0, 45)
|
||||
end)
|
||||
S:HandleButton(f.Option2, true)
|
||||
|
||||
f.Option3 = CreateFrame("Button", "InstallOption3Button", f, "UIPanelButtonTemplate")
|
||||
f.Option3:Size(100, 30)
|
||||
f.Option3:Point("LEFT", f.Option2, "RIGHT", 4, 0)
|
||||
f.Option3:SetText("")
|
||||
f.Option3:Hide()
|
||||
f.Option3:SetScript("OnShow", function()
|
||||
f.Option1:Width(100)
|
||||
f.Option1:ClearAllPoints()
|
||||
f.Option1:Point("RIGHT", f.Option2, "LEFT", -4, 0)
|
||||
f.Option2:Width(100)
|
||||
f.Option2:ClearAllPoints()
|
||||
f.Option2:Point("BOTTOM", f, "BOTTOM", 0, 45)
|
||||
end)
|
||||
f.Option3:SetScript("OnHide", function()
|
||||
f.Option1:Width(160)
|
||||
f.Option1:ClearAllPoints()
|
||||
f.Option1:Point("BOTTOM", 0, 45)
|
||||
f.Option2:Width(110)
|
||||
f.Option2:ClearAllPoints()
|
||||
f.Option2:Point("BOTTOMLEFT", f, "BOTTOM", 4, 45)
|
||||
end)
|
||||
S:HandleButton(f.Option3, true)
|
||||
|
||||
f.Option4 = CreateFrame("Button", "InstallOption4Button", f, "UIPanelButtonTemplate")
|
||||
f.Option4:Size(100, 30)
|
||||
f.Option4:Point("LEFT", f.Option3, "RIGHT", 4, 0)
|
||||
f.Option4:SetText("")
|
||||
f.Option4:Hide()
|
||||
f.Option4:SetScript("OnShow", function()
|
||||
f.Option1:Width(100)
|
||||
f.Option1:ClearAllPoints()
|
||||
f.Option1:Point("RIGHT", f.Option2, "LEFT", -4, 0)
|
||||
f.Option2:Width(100)
|
||||
f.Option2:ClearAllPoints()
|
||||
f.Option2:Point("BOTTOMRIGHT", f, "BOTTOM", -4, 45)
|
||||
end)
|
||||
f.Option4:SetScript("OnHide", function()
|
||||
f.Option1:Width(160)
|
||||
f.Option1:ClearAllPoints()
|
||||
f.Option1:Point("BOTTOM", 0, 45)
|
||||
f.Option2:Width(110)
|
||||
f.Option2:ClearAllPoints()
|
||||
f.Option2:Point("BOTTOMLEFT", f, "BOTTOM", 4, 45)
|
||||
end)
|
||||
S:HandleButton(f.Option4, true)
|
||||
|
||||
f.SubTitle = f:CreateFontString(nil, "OVERLAY")
|
||||
f.SubTitle:FontTemplate(nil, 15, nil)
|
||||
f.SubTitle:Point("TOP", 0, -40)
|
||||
|
||||
f.Desc1 = f:CreateFontString(nil, "OVERLAY")
|
||||
f.Desc1:FontTemplate()
|
||||
f.Desc1:Point("TOPLEFT", 20, -75)
|
||||
f.Desc1:Width(f:GetWidth() - 40)
|
||||
|
||||
f.Desc2 = f:CreateFontString(nil, "OVERLAY")
|
||||
f.Desc2:FontTemplate()
|
||||
f.Desc2:Point("TOPLEFT", 20, -125)
|
||||
f.Desc2:Width(f:GetWidth() - 40)
|
||||
|
||||
f.Desc3 = f:CreateFontString(nil, "OVERLAY")
|
||||
f.Desc3:FontTemplate()
|
||||
f.Desc3:Point("TOPLEFT", 20, -175)
|
||||
f.Desc3:Width(f:GetWidth() - 40)
|
||||
|
||||
local closeButton = CreateFrame("Button", "InstallCloseButton", f, "UIPanelCloseButton")
|
||||
closeButton:Point("TOPRIGHT", f, "TOPRIGHT")
|
||||
closeButton:SetScript("OnClick", function() f:Hide() end)
|
||||
S:HandleCloseButton(closeButton)
|
||||
|
||||
f.tutorialImage = f:CreateTexture("InstallTutorialImage", "OVERLAY")
|
||||
f.tutorialImage:Size(256, 128)
|
||||
f.tutorialImage:SetTexture(E.Media.Textures.Logo)
|
||||
f.tutorialImage:Point("BOTTOM", 0, 70)
|
||||
end
|
||||
|
||||
ElvUIInstallFrame:Show()
|
||||
NextPage()
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||
<Script file="Core.lua"/>
|
||||
<Script file="Math.lua"/>
|
||||
<Script file="API.lua"/>
|
||||
<Script file="AprilFools.lua"/>
|
||||
<Script file="Fonts.lua"/>
|
||||
<Script file="Install.lua"/>
|
||||
<Script file="PluginInstaller.lua"/>
|
||||
<Script file="PixelPerfect.lua"/>
|
||||
<Script file="Toolkit.lua"/>
|
||||
<Script file="StatusReport.lua"/>
|
||||
<Script file="Commands.lua"/>
|
||||
<Script file="StaticPopups.lua"/>
|
||||
<Script file="Animation.lua"/>
|
||||
<Script file="Smoothie.lua"/>
|
||||
<Script file="Movers.lua"/>
|
||||
<Script file="Config.lua"/>
|
||||
<Script file="Tutorials.lua"/>
|
||||
<Script file="Distributor.lua"/>
|
||||
<Script file="Dropdown.lua"/>
|
||||
<Script file="Cooldowns.lua"/>
|
||||
<Script file="ModuleCopy.lua"/>
|
||||
<Script file="Tags.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,460 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
|
||||
--Lua functions
|
||||
local pairs, ipairs = pairs, ipairs
|
||||
local next, select, type, unpack = next, select, type, unpack
|
||||
local tonumber, tostring = tonumber, tostring
|
||||
local abs, ceil, floor, fmod, modf = math.abs, math.ceil, math.floor, math.fmod, math.modf
|
||||
local byte, format, gmatch, gsub, strupper, strsub = string.byte, string.format, string.gmatch, string.gsub, strupper, strsub
|
||||
local utf8sub = string.utf8sub
|
||||
local tinsert, tremove, wipe = table.insert, table.remove, table.wipe
|
||||
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local GetScreenWidth, GetScreenHeight = GetScreenWidth, GetScreenHeight
|
||||
|
||||
E.ShortPrefixValues = {}
|
||||
E.ShortPrefixStyles = {
|
||||
["CHINESE"] = {{1e8, "Y"}, {1e4, "W"}},
|
||||
["ENGLISH"] = {{1e12, "T"}, {1e9, "B"}, {1e6, "M"}, {1e3, "K"}},
|
||||
["GERMAN"] = {{1e12, "Bio"}, {1e9, "Mrd"}, {1e6, "Mio"}, {1e3, "Tsd"}},
|
||||
["KOREAN"] = {{1e8, "억"}, {1e4, "만"}, {1e3, "천"}},
|
||||
["METRIC"] = {{1e12, "T"}, {1e9, "G"}, {1e6, "M"}, {1e3, "k"}}
|
||||
}
|
||||
|
||||
E.GetFormattedTextStyles = {
|
||||
["CURRENT"] = "%s",
|
||||
["CURRENT_MAX"] = "%s - %s",
|
||||
["CURRENT_PERCENT"] = "%s - %.1f%%",
|
||||
["CURRENT_MAX_PERCENT"] = "%s - %s | %.1f%%",
|
||||
["PERCENT"] = "%.1f%%",
|
||||
["DEFICIT"] = "-%s"
|
||||
}
|
||||
|
||||
function E:BuildPrefixValues()
|
||||
if next(E.ShortPrefixValues) then wipe(E.ShortPrefixValues) end
|
||||
|
||||
E.ShortPrefixValues = E:CopyTable(E.ShortPrefixValues, E.ShortPrefixStyles[E.db.general.numberPrefixStyle])
|
||||
E.ShortValueDec = format("%%.%df", E.db.general.decimalLength or 1)
|
||||
|
||||
for _, style in ipairs(E.ShortPrefixValues) do
|
||||
style[2] = E.ShortValueDec..style[2]
|
||||
end
|
||||
|
||||
local gftDec = tostring(E.db.general.decimalLength or 1)
|
||||
for style, str in pairs(E.GetFormattedTextStyles) do
|
||||
E.GetFormattedTextStyles[style] = gsub(str, "%d", gftDec)
|
||||
end
|
||||
end
|
||||
|
||||
--Return short value of a number
|
||||
function E:ShortValue(v)
|
||||
local abs_v = v < 0 and -v or v
|
||||
for i = 1, #E.ShortPrefixValues do
|
||||
if abs_v >= E.ShortPrefixValues[i][1] then
|
||||
return format(E.ShortPrefixValues[i][2], v / E.ShortPrefixValues[i][1])
|
||||
end
|
||||
end
|
||||
|
||||
return format("%.0f", v)
|
||||
end
|
||||
|
||||
function E:IsEvenNumber(num)
|
||||
return num % 2 == 0
|
||||
end
|
||||
|
||||
-- http://www.wowwiki.com/ColorGradient
|
||||
function E:ColorGradient(perc, ...)
|
||||
if perc >= 1 then
|
||||
return select(select("#", ...) - 2, ...)
|
||||
elseif perc <= 0 then
|
||||
return ...
|
||||
end
|
||||
|
||||
local num = select("#", ...) / 3
|
||||
local segment, relperc = modf(perc*(num - 1))
|
||||
local r1, g1, b1, r2, g2, b2 = select((segment*3) + 1, ...)
|
||||
|
||||
return r1 + (r2 - r1)*relperc, g1 + (g2 - g1)*relperc, b1 + (b2 - b1)*relperc
|
||||
end
|
||||
|
||||
--Return rounded number
|
||||
function E:Round(num, idp)
|
||||
if idp and idp > 0 then
|
||||
local mult = 10 ^ idp
|
||||
return floor(num * mult + 0.5) / mult
|
||||
end
|
||||
return floor(num + 0.5)
|
||||
end
|
||||
|
||||
--Truncate a number off to n places
|
||||
function E:Truncate(v, decimals)
|
||||
return v - (v % (0.1 ^ (decimals or 0)))
|
||||
end
|
||||
|
||||
--RGB to Hex
|
||||
function E:RGBToHex(r, g, b)
|
||||
r = r <= 1 and r >= 0 and r or 1
|
||||
g = g <= 1 and g >= 0 and g or 1
|
||||
b = b <= 1 and b >= 0 and b or 1
|
||||
return format("|cff%02x%02x%02x", r*255, g*255, b*255)
|
||||
end
|
||||
|
||||
--Hex to RGB
|
||||
function E:HexToRGB(hex)
|
||||
local rhex, ghex, bhex = strsub(hex, 1, 2), strsub(hex, 3, 4), strsub(hex, 5, 6)
|
||||
return tonumber(rhex, 16), tonumber(ghex, 16), tonumber(bhex, 16)
|
||||
end
|
||||
|
||||
--From http://wow.gamepedia.com/UI_coordinates
|
||||
function E:FramesOverlap(frameA, frameB)
|
||||
if not frameA or not frameB then return end
|
||||
|
||||
local sA, sB = frameA:GetEffectiveScale(), frameB:GetEffectiveScale()
|
||||
if not sA or not sB then return end
|
||||
|
||||
local frameALeft, frameARight, frameABottom, frameATop = frameA:GetLeft(), frameA:GetRight(), frameA:GetBottom(), frameA:GetTop()
|
||||
local frameBLeft, frameBRight, frameBBottom, frameBTop = frameB:GetLeft(), frameB:GetRight(), frameB:GetBottom(), frameB:GetTop()
|
||||
if not (frameALeft and frameARight and frameABottom and frameATop) then return end
|
||||
if not (frameBLeft and frameBRight and frameBBottom and frameBTop) then return end
|
||||
|
||||
return ((frameALeft*sA) < (frameBRight*sB)) and ((frameBLeft*sB) < (frameARight*sA)) and ((frameABottom*sA) < (frameBTop*sB)) and ((frameBBottom*sB) < (frameATop*sA))
|
||||
end
|
||||
|
||||
function E:GetScreenQuadrant(frame)
|
||||
local x, y = frame:GetCenter()
|
||||
local screenWidth = GetScreenWidth()
|
||||
local screenHeight = GetScreenHeight()
|
||||
|
||||
if not (x and y) then
|
||||
return "UNKNOWN", frame:GetName()
|
||||
end
|
||||
|
||||
local point
|
||||
if (x > (screenWidth / 3) and x < (screenWidth / 3)*2) and y > (screenHeight / 3)*2 then
|
||||
point = "TOP"
|
||||
elseif x < (screenWidth / 3) and y > (screenHeight / 3)*2 then
|
||||
point = "TOPLEFT"
|
||||
elseif x > (screenWidth / 3)*2 and y > (screenHeight / 3)*2 then
|
||||
point = "TOPRIGHT"
|
||||
elseif (x > (screenWidth / 3) and x < (screenWidth / 3)*2) and y < (screenHeight / 3) then
|
||||
point = "BOTTOM"
|
||||
elseif x < (screenWidth / 3) and y < (screenHeight / 3) then
|
||||
point = "BOTTOMLEFT"
|
||||
elseif x > (screenWidth / 3)*2 and y < (screenHeight / 3) then
|
||||
point = "BOTTOMRIGHT"
|
||||
elseif x < (screenWidth / 3) and (y > (screenHeight / 3) and y < (screenHeight / 3)*2) then
|
||||
point = "LEFT"
|
||||
elseif x > (screenWidth / 3)*2 and y < (screenHeight / 3)*2 and y > (screenHeight / 3) then
|
||||
point = "RIGHT"
|
||||
else
|
||||
point = "CENTER"
|
||||
end
|
||||
|
||||
return point
|
||||
end
|
||||
|
||||
function E:GetXYOffset(position, override)
|
||||
local default = E.Spacing
|
||||
local x, y = override or default, override or default
|
||||
|
||||
if position == "TOP" then
|
||||
return 0, y
|
||||
elseif position == "TOPLEFT" then
|
||||
return x, y
|
||||
elseif position == "TOPRIGHT" then
|
||||
return -x, y
|
||||
elseif position == "BOTTOM" then
|
||||
return 0, -y
|
||||
elseif position == "BOTTOMLEFT" then
|
||||
return x, -y
|
||||
elseif position == "BOTTOMRIGHT" then
|
||||
return -x, -y
|
||||
elseif position == "LEFT" then
|
||||
return -x, 0
|
||||
elseif position == "RIGHT" then
|
||||
return x, 0
|
||||
elseif position == "CENTER" then
|
||||
return 0, 0
|
||||
end
|
||||
end
|
||||
|
||||
function E:GetFormattedText(style, min, max, dec)
|
||||
if max == 0 then max = 1 end
|
||||
|
||||
if style == "CURRENT" or ((style == "CURRENT_MAX" or style == "CURRENT_MAX_PERCENT" or style == "CURRENT_PERCENT") and min == max) then
|
||||
return format(E.GetFormattedTextStyles.CURRENT, E:ShortValue(min, dec))
|
||||
else
|
||||
local useStyle = E.GetFormattedTextStyles[style]
|
||||
if not useStyle then return end
|
||||
|
||||
if style == "DEFICIT" then
|
||||
local deficit = max - min
|
||||
return (deficit > 0 and format(useStyle, E:ShortValue(deficit, dec))) or ""
|
||||
elseif style == "CURRENT_MAX" then
|
||||
return format(useStyle, E:ShortValue(min, dec), E:ShortValue(max, dec))
|
||||
elseif style == "PERCENT" or style == "CURRENT_PERCENT" or style == "CURRENT_MAX_PERCENT" then
|
||||
if dec then useStyle = gsub(useStyle, "%d", tonumber(dec) or 0) end
|
||||
local perc = min / max * 100
|
||||
|
||||
if style == "PERCENT" then
|
||||
return format(useStyle, perc)
|
||||
elseif style == "CURRENT_PERCENT" then
|
||||
return format(useStyle, E:ShortValue(min, dec), perc)
|
||||
elseif style == "CURRENT_MAX_PERCENT" then
|
||||
return format(useStyle, E:ShortValue(min, dec), E:ShortValue(max, dec), perc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:ShortenString(str, numChars, dots)
|
||||
local bytes = #str
|
||||
if bytes <= numChars then
|
||||
return str
|
||||
else
|
||||
local len, pos = 0, 1
|
||||
while pos <= bytes do
|
||||
len = len + 1
|
||||
local c = byte(str, pos)
|
||||
if c > 0 and c <= 127 then
|
||||
pos = pos + 1
|
||||
elseif c >= 192 and c <= 223 then
|
||||
pos = pos + 2
|
||||
elseif c >= 224 and c <= 239 then
|
||||
pos = pos + 3
|
||||
elseif c >= 240 and c <= 247 then
|
||||
pos = pos + 4
|
||||
end
|
||||
if len == numChars then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if len == numChars and pos <= bytes then
|
||||
return strsub(str, 1, pos - 1)..(dots and "..." or "")
|
||||
else
|
||||
return str
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:AbbreviateString(str, allUpper)
|
||||
local newString = ""
|
||||
for word in gmatch(str, "[^%s]+") do
|
||||
word = utf8sub(word, 1, 1) --get only first letter of each word
|
||||
if allUpper then word = strupper(word) end
|
||||
newString = newString..word
|
||||
end
|
||||
|
||||
return newString
|
||||
end
|
||||
|
||||
function E:WaitFunc(elapsed)
|
||||
local total = #E.WaitTable
|
||||
local i = 1
|
||||
|
||||
while i <= total do
|
||||
local data = E.WaitTable[i]
|
||||
|
||||
if data[1] > elapsed then
|
||||
data[1] = data[1] - elapsed
|
||||
i = i + 1
|
||||
else
|
||||
tremove(E.WaitTable, i)
|
||||
|
||||
if data[3] then
|
||||
if data[3] > 1 then
|
||||
data[2](unpack(data[4], 1, data[3]))
|
||||
else
|
||||
data[2](data[4])
|
||||
end
|
||||
else
|
||||
data[2]()
|
||||
end
|
||||
|
||||
total = total - 1
|
||||
end
|
||||
end
|
||||
|
||||
if #E.WaitTable == 0 then
|
||||
self:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
E.WaitTable = {}
|
||||
E.WaitFrame = CreateFrame("Frame", "ElvUI_WaitFrame", UIParent)
|
||||
E.WaitFrame:SetScript("OnUpdate", E.WaitFunc)
|
||||
|
||||
--Add time before calling a function
|
||||
function E:Delay(delay, func, ...)
|
||||
if type(delay) ~= "number" then
|
||||
error(format("Bad argument #1 to 'Delay' (number expected, got %s)", delay ~= nil and type(delay) or "no value"), 2)
|
||||
elseif type(func) ~= "function" then
|
||||
error(format("Bad argument #2 to 'Delay' (function expected, got %s)", func ~= nil and type(func) or "no value"), 2)
|
||||
end
|
||||
|
||||
local argCount = select("#", ...)
|
||||
|
||||
tinsert(E.WaitTable, {
|
||||
delay,
|
||||
func,
|
||||
argCount > 0 and argCount,
|
||||
argCount == 1 and (...) or argCount > 1 and {...}
|
||||
})
|
||||
|
||||
E.WaitFrame:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function E:StringTitle(str)
|
||||
return gsub(str, "(.)", strupper, 1)
|
||||
end
|
||||
|
||||
E.TimeThreshold = 3
|
||||
|
||||
E.TimeColors = { --aura time colors
|
||||
[0] = "|cffeeeeee", --days
|
||||
[1] = "|cffeeeeee", --hours
|
||||
[2] = "|cffeeeeee", --minutes
|
||||
[3] = "|cffeeeeee", --seconds
|
||||
[4] = "|cfffe0000", --expire (fade timer)
|
||||
[5] = "|cff909090", --mmss
|
||||
[6] = "|cff707070", --hhmm
|
||||
}
|
||||
|
||||
E.TimeFormats = { -- short / indicator color
|
||||
[0] = {"%dd", "%d%sd|r"},
|
||||
[1] = {"%dh", "%d%sh|r"},
|
||||
[2] = {"%dm", "%d%sm|r"},
|
||||
[3] = {"%ds", "%d%ss|r"},
|
||||
[4] = {"%.1fs", "%.1f%ss|r"},
|
||||
[5] = {"%d:%02d", "%d%s:|r%02d"}, --mmss
|
||||
[6] = {"%d:%02d", "%d%s:|r%02d"}, --hhmm
|
||||
}
|
||||
|
||||
for _, x in pairs(E.TimeFormats) do
|
||||
x[3] = gsub(x[1], "s$", "") -- 1 without seconds
|
||||
x[4] = gsub(x[2], "%%ss", "%%s") -- 2 without seconds
|
||||
end
|
||||
|
||||
E.TimeIndicatorColors = {
|
||||
[0] = "|cff00b3ff",
|
||||
[1] = "|cff00b3ff",
|
||||
[2] = "|cff00b3ff",
|
||||
[3] = "|cff00b3ff",
|
||||
[4] = "|cff00b3ff",
|
||||
[5] = "|cff00b3ff",
|
||||
[6] = "|cff00b3ff",
|
||||
}
|
||||
|
||||
local DAY, HOUR, MINUTE = 86400, 3600, 60 --used for calculating aura time text
|
||||
local DAYISH, HOURISH, MINUTEISH = HOUR * 23.5, MINUTE * 59.5, 59.5 --used for caclculating aura time at transition points
|
||||
local HALFDAYISH, HALFHOURISH, HALFMINUTEISH = DAY/2 + 0.5, HOUR/2 + 0.5, MINUTE/2 + 0.5 --used for calculating next update times
|
||||
|
||||
-- will return the the value to display, the formatter id to use and calculates the next update for the Aura
|
||||
function E:GetTimeInfo(s, threshhold, hhmm, mmss)
|
||||
if s < MINUTE then
|
||||
if s >= threshhold then
|
||||
return floor(s), 3, 0.51
|
||||
else
|
||||
return s, 4, 0.051
|
||||
end
|
||||
elseif s < HOUR then
|
||||
if mmss and s < mmss then
|
||||
return s/MINUTE, 5, 0.51, s%MINUTE
|
||||
else
|
||||
local minutes = floor((s/MINUTE)+.5)
|
||||
if hhmm and s < (hhmm * MINUTE) and 60 < minutes then
|
||||
return s/HOUR, 6, minutes > 1 and (s - (minutes*MINUTE - HALFMINUTEISH)) or (s - MINUTEISH), minutes%MINUTE
|
||||
else
|
||||
return ceil(s / MINUTE), 2, minutes > 1 and (s - (minutes*MINUTE - HALFMINUTEISH)) or (s - MINUTEISH)
|
||||
end
|
||||
end
|
||||
elseif s < DAY then
|
||||
if mmss and s < mmss then
|
||||
return s/MINUTE, 5, 0.51, s%MINUTE
|
||||
else
|
||||
local minutes = floor((s/MINUTE)+.5)
|
||||
if hhmm and s < (hhmm * MINUTE) and 60 < minutes then
|
||||
return s/HOUR, 6, minutes > 1 and (s - (minutes*MINUTE - HALFMINUTEISH)) or (s - MINUTEISH), minutes%MINUTE
|
||||
else
|
||||
local hours = floor((s/HOUR)+.5)
|
||||
return ceil(s / HOUR), 1, hours > 1 and (s - (hours*HOUR - HALFHOURISH)) or (s - HOURISH)
|
||||
end
|
||||
end
|
||||
else
|
||||
local days = floor((s/DAY)+.5)
|
||||
return ceil(s / DAY), 0, days > 1 and (s - (days*DAY - HALFDAYISH)) or (s - DAYISH)
|
||||
end
|
||||
end
|
||||
|
||||
--Money text formatting, code taken from Scrooge by thelibrarian (http://www.wowace.com/addons/scrooge/)
|
||||
local COLOR_COPPER, COLOR_SILVER, COLOR_GOLD = "|cffeda55f", "|cffc7c7cf", "|cffffd700"
|
||||
local ICON_COPPER = "|TInterface\\MoneyFrame\\UI-CopperIcon:12:12|t"
|
||||
local ICON_SILVER = "|TInterface\\MoneyFrame\\UI-SilverIcon:12:12|t"
|
||||
local ICON_GOLD = "|TInterface\\MoneyFrame\\UI-GoldIcon:12:12|t"
|
||||
function E:FormatMoney(amount, style, textonly)
|
||||
local coppername = textonly and L["copperabbrev"] or ICON_COPPER
|
||||
local silvername = textonly and L["silverabbrev"] or ICON_SILVER
|
||||
local goldname = textonly and L["goldabbrev"] or ICON_GOLD
|
||||
|
||||
local value = abs(amount)
|
||||
local gold = floor(value / 10000)
|
||||
local silver = floor(fmod(value / 100, 100))
|
||||
local copper = floor(fmod(value, 100))
|
||||
|
||||
if not style or style == "SMART" then
|
||||
local str = ""
|
||||
if gold > 0 then str = format("%d%s%s", gold, goldname, (silver > 0 or copper > 0) and " " or "") end
|
||||
if silver > 0 then str = format("%s%d%s%s", str, silver, silvername, copper > 0 and " " or "") end
|
||||
if copper > 0 or value == 0 then str = format("%s%d%s", str, copper, coppername) end
|
||||
return str
|
||||
end
|
||||
|
||||
if style == "FULL" then
|
||||
if gold > 0 then
|
||||
return format("%d%s %d%s %d%s", gold, goldname, silver, silvername, copper, coppername)
|
||||
elseif silver > 0 then
|
||||
return format("%d%s %d%s", silver, silvername, copper, coppername)
|
||||
else
|
||||
return format("%d%s", copper, coppername)
|
||||
end
|
||||
elseif style == "SHORT" then
|
||||
if gold > 0 then
|
||||
return format("%.1f%s", amount / 10000, goldname)
|
||||
elseif silver > 0 then
|
||||
return format("%.1f%s", amount / 100, silvername)
|
||||
else
|
||||
return format("%d%s", amount, coppername)
|
||||
end
|
||||
elseif style == "SHORTINT" then
|
||||
if gold > 0 then
|
||||
return format("%d%s", gold, goldname)
|
||||
elseif silver > 0 then
|
||||
return format("%d%s", silver, silvername)
|
||||
else
|
||||
return format("%d%s", copper, coppername)
|
||||
end
|
||||
elseif style == "CONDENSED" then
|
||||
if gold > 0 then
|
||||
return format("%s%d|r.%s%02d|r.%s%02d|r", COLOR_GOLD, gold, COLOR_SILVER, silver, COLOR_COPPER, copper)
|
||||
elseif silver > 0 then
|
||||
return format("%s%d|r.%s%02d|r", COLOR_SILVER, silver, COLOR_COPPER, copper)
|
||||
else
|
||||
return format("%s%d|r", COLOR_COPPER, copper)
|
||||
end
|
||||
elseif style == "BLIZZARD" then
|
||||
if gold > 0 then
|
||||
return format("%s%s %d%s %d%s", gold, goldname, silver, silvername, copper, coppername)
|
||||
elseif silver > 0 then
|
||||
return format("%d%s %d%s", silver, silvername, copper, coppername)
|
||||
else
|
||||
return format("%d%s", copper, coppername)
|
||||
end
|
||||
end
|
||||
|
||||
-- Shouldn't be here; punt
|
||||
return self:FormatMoney(amount, "SMART")
|
||||
end
|
||||
@@ -0,0 +1,276 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local MC = E:GetModule("ModuleCopy")
|
||||
|
||||
--Lua functions
|
||||
local pairs, next, type = pairs, next, type
|
||||
local format, error = format, error
|
||||
--WoW API / Variables
|
||||
-- GLOBALS: ElvDB
|
||||
|
||||
--This table to reserve settings names in E.global.profileCopy. Used in export/imports functions
|
||||
--Pligins can add own values for their internal settings for safechecks here
|
||||
MC.InternalOptions = {
|
||||
["selected"] = true,
|
||||
["movers"] = true,
|
||||
}
|
||||
|
||||
--Default template for a config group for a single module.
|
||||
--Contains header, general group toggle (shown only if the setting actually exists) and imports button.
|
||||
--Usage as seen in ElvUI_OptionsUI\modulecopy.lua
|
||||
function MC:CreateModuleConfigGroup(Name, section, pluginSection)
|
||||
local config = {
|
||||
order = 10,
|
||||
type = "group",
|
||||
name = Name,
|
||||
args = {
|
||||
header = {
|
||||
order = 0,
|
||||
type = "header",
|
||||
name = Name
|
||||
},
|
||||
general = {
|
||||
order = 1,
|
||||
type = "toggle",
|
||||
name = L["General"]
|
||||
},
|
||||
PreButtonSpacer = {
|
||||
order = 200,
|
||||
type = "description",
|
||||
name = ""
|
||||
},
|
||||
import = {
|
||||
order = 201,
|
||||
type = "execute",
|
||||
name = L["Import Now"],
|
||||
func = function()
|
||||
E.PopupDialogs.MODULE_COPY_CONFIRM.text = format(L["You are going to copy settings for |cffD3CF00\"%s\"|r from |cff4beb2c\"%s\"|r profile to your current |cff4beb2c\"%s\"|r profile. Are you sure?"], Name, E.global.profileCopy.selected, ElvDB.profileKeys[E.myname.." - "..E.myrealm])
|
||||
E.PopupDialogs.MODULE_COPY_CONFIRM.OnAccept = function()
|
||||
MC:ImportFromProfile(section, pluginSection)
|
||||
end
|
||||
E:StaticPopup_Show("MODULE_COPY_CONFIRM")
|
||||
end
|
||||
},
|
||||
export = {
|
||||
order = 202,
|
||||
type = "execute",
|
||||
name = L["Export Now"],
|
||||
func = function()
|
||||
E.PopupDialogs.MODULE_COPY_CONFIRM.text = format(L["You are going to copy settings for |cffD3CF00\"%s\"|r from your current |cff4beb2c\"%s\"|r profile to |cff4beb2c\"%s\"|r profile. Are you sure?"], Name, ElvDB.profileKeys[E.myname.." - "..E.myrealm], E.global.profileCopy.selected)
|
||||
E.PopupDialogs.MODULE_COPY_CONFIRM.OnAccept = function()
|
||||
MC:ExportToProfile(section, pluginSection)
|
||||
end
|
||||
E:StaticPopup_Show("MODULE_COPY_CONFIRM")
|
||||
end
|
||||
}
|
||||
}
|
||||
}
|
||||
if pluginSection then
|
||||
config.args.general.hidden = function(info) return E.global.profileCopy[pluginSection][section][ info[#info] ] == nil end
|
||||
config.args.general.get = function(info) return E.global.profileCopy[pluginSection][section][ info[#info] ] end
|
||||
config.args.general.set = function(info, value) E.global.profileCopy[pluginSection][section][ info[#info] ] = value end
|
||||
else
|
||||
config.args.general.hidden = function(info) return E.global.profileCopy[section][ info[#info] ] == nil end
|
||||
config.args.general.get = function(info) return E.global.profileCopy[section][ info[#info] ] end
|
||||
config.args.general.set = function(info, value) E.global.profileCopy[section][ info[#info] ] = value end
|
||||
end
|
||||
|
||||
return config
|
||||
end
|
||||
|
||||
function MC:CreateMoversConfigGroup()
|
||||
local config = {
|
||||
header = {
|
||||
order = 0,
|
||||
type = "header",
|
||||
name = L["On screen positions for different elements."]
|
||||
},
|
||||
PreButtonSpacer = {
|
||||
order = 200,
|
||||
type = "description",
|
||||
name = ""
|
||||
},
|
||||
import = {
|
||||
order = 201,
|
||||
type = "execute",
|
||||
name = L["Import Now"],
|
||||
func = function()
|
||||
E.PopupDialogs.MODULE_COPY_CONFIRM.text = format(L["You are going to copy settings for |cffD3CF00\"%s\"|r from |cff4beb2c\"%s\"|r profile to your current |cff4beb2c\"%s\"|r profile. Are you sure?"], L["Movers"], E.global.profileCopy.selected, ElvDB.profileKeys[E.myname.." - "..E.myrealm])
|
||||
E.PopupDialogs.MODULE_COPY_CONFIRM.OnAccept = function()
|
||||
MC:CopyMovers("import")
|
||||
end
|
||||
E:StaticPopup_Show("MODULE_COPY_CONFIRM")
|
||||
end
|
||||
},
|
||||
export = {
|
||||
order = 202,
|
||||
type = "execute",
|
||||
name = L["Export Now"],
|
||||
func = function()
|
||||
E.PopupDialogs.MODULE_COPY_CONFIRM.text = format(L["You are going to copy settings for |cffD3CF00\"%s\"|r from your current |cff4beb2c\"%s\"|r profile to |cff4beb2c\"%s\"|r profile. Are you sure?"], L["Movers"], ElvDB.profileKeys[E.myname.." - "..E.myrealm], E.global.profileCopy.selected)
|
||||
E.PopupDialogs.MODULE_COPY_CONFIRM.OnAccept = function()
|
||||
MC:CopyMovers("export")
|
||||
end
|
||||
E:StaticPopup_Show("MODULE_COPY_CONFIRM")
|
||||
end
|
||||
}
|
||||
}
|
||||
for moverName, data in pairs(E.CreatedMovers) do
|
||||
if not G.profileCopy.movers[moverName] then G.profileCopy.movers[moverName] = false end
|
||||
config[moverName] = {
|
||||
order = 1,
|
||||
type = "toggle",
|
||||
name = data.text,
|
||||
get = function(info) return E.global.profileCopy.movers[moverName] end,
|
||||
set = function(info, value) E.global.profileCopy.movers[moverName] = value end
|
||||
}
|
||||
end
|
||||
for moverName, data in pairs(E.DisabledMovers) do
|
||||
if not G.profileCopy.movers[moverName] then G.profileCopy.movers[moverName] = false end
|
||||
config[moverName] = {
|
||||
order = 1,
|
||||
type = "toggle",
|
||||
name = data.text,
|
||||
get = function(info) return E.global.profileCopy.movers[moverName] end,
|
||||
set = function(info, value) E.global.profileCopy.movers[moverName] = value end
|
||||
}
|
||||
end
|
||||
|
||||
return config
|
||||
end
|
||||
|
||||
function MC:CopyTable(CopyFrom, CopyTo, CopyDefault, module)
|
||||
for key, value in pairs(CopyTo) do
|
||||
if type(value) ~= "table" then
|
||||
if module == true or (type(module) == "table" and (module.general == nil or (not CopyTo.general and module.general))) then --Some dark magic of a logic to figure out stuff
|
||||
--This check is to see if the profile we are copying from has keys absent from defaults.
|
||||
--If key exists, then copy. If not, then clear obsolite key from the profile.
|
||||
if CopyDefault[key] ~= nil then
|
||||
CopyTo[key] = CopyFrom[key] or CopyDefault[key]
|
||||
else
|
||||
CopyFrom[key] = nil
|
||||
end
|
||||
end
|
||||
else
|
||||
if module == true then --Copy over entire section of profile subgroup
|
||||
E:CopyTable(CopyTo, CopyDefault)
|
||||
E:CopyTable(CopyTo, CopyFrom)
|
||||
elseif type(module) == "table" and module[key] ~= nil then
|
||||
--Making sure tables actually exist in profiles (e.g absent values in ElvDB.profiles are for default values)
|
||||
CopyFrom[key], CopyTo[key] = MC:TablesExist(CopyFrom[key], CopyTo[key], CopyDefault[key])
|
||||
--If key exists, then copy. If not, then clear obsolite key from the profile.
|
||||
--Someone should double check this logic. Cause for single keys it is fine, but I'm no sure bout whole tables @Darth
|
||||
if CopyFrom[key] ~= nil then
|
||||
MC:CopyTable(CopyFrom[key], CopyTo[key], CopyDefault[key], module[key])
|
||||
else
|
||||
CopyTo[key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
* Valid copy templates should be as follows
|
||||
G.profileCopy[YourOptionGroupName] = {
|
||||
[SubGroupName1] = true,
|
||||
[SubGroupName2] = true,
|
||||
...
|
||||
}
|
||||
* For example
|
||||
G.profileCopy.auras = {
|
||||
["general"] = true,
|
||||
["buffs"] = true,
|
||||
["debuffs"] = true,
|
||||
["cooldown"] = true,
|
||||
}
|
||||
* "general" key can refer to a similar named subtable or all non-table variables inside your group
|
||||
* If you leave the table as G.profileCopy[YourOptionGroupName] = {}, this will result in no valid copy template error.
|
||||
* If set to G.profileCopy[YourOptionGroupName] = true, then this will copy everything without selecting
|
||||
any particular subcategory from your settings table.
|
||||
* Plugins can use "pluginSection" argument to determain their own table if they keep settings apart from core ElvUI settings.
|
||||
Examples S&L uses "sle" table, MerathilisUI uses "mui" table, BenikUI uses "benikui" and core table
|
||||
]]
|
||||
|
||||
function MC:TablesExist(CopyFrom, CopyTo, CopyDefault)
|
||||
if not CopyFrom then CopyFrom = CopyDefault end
|
||||
if not CopyTo then CopyTo = CopyDefault end
|
||||
return CopyFrom, CopyTo
|
||||
end
|
||||
|
||||
function MC:ImportFromProfile(section, pluginSection)
|
||||
--Some checks for the occasion someone passes wrong stuff
|
||||
if not section then error("No profile section provided. Usage MC:ImportFromProfile(\"section\")") end
|
||||
if not pluginSection and MC.InternalOptions[section] then error(format("Section name could not be \"%s\". This name is reserved for internal setting"), section) end
|
||||
if pluginSection and (MC.InternalOptions[pluginSection] and MC.InternalOptions[pluginSection][section]) then error(format("Section name for plugin group \"%s\" could not be \"%s\". This name is reserved for internal setting"), pluginSection, section) end
|
||||
|
||||
local module = pluginSection and E.global.profileCopy[pluginSection][section] or E.global.profileCopy[section]
|
||||
if not module then error(format("Provided section name \"%s\" does not have a template for profile copy.", section)) end
|
||||
--Starting digging through the settings
|
||||
local CopyFrom = pluginSection and (ElvDB.profiles[E.global.profileCopy.selected][pluginSection] and ElvDB.profiles[E.global.profileCopy.selected][pluginSection][section] or P[pluginSection][section]) or ElvDB.profiles[E.global.profileCopy.selected][section]
|
||||
local CopyTo = pluginSection and E.db[pluginSection][section] or E.db[section]
|
||||
local CopyDefault = pluginSection and P[pluginSection][section] or P[section]
|
||||
--Making sure tables actually exist in profiles (e.g absent values in ElvDB.profiles are for default values)
|
||||
CopyFrom, CopyTo = MC:TablesExist(CopyFrom, CopyTo, CopyDefault)
|
||||
if type(module) == "table" and next(module) then --This module is not an empty table
|
||||
MC:CopyTable(CopyFrom, CopyTo, CopyDefault, module)
|
||||
elseif type(module) == "boolean" then --Copy over entire section of profile subgroup
|
||||
E:CopyTable(CopyTo, CopyDefault)
|
||||
E:CopyTable(CopyTo, CopyFrom)
|
||||
else
|
||||
error(format("Provided section name \"%s\" does not have a valid copy template.", section))
|
||||
end
|
||||
E:UpdateAll(true)
|
||||
end
|
||||
|
||||
function MC:ExportToProfile(section, pluginSection)
|
||||
--Some checks for the occasion someone passes wrong stuff
|
||||
if not section then error("No profile section provided. Usage MC:ExportToProfile(\"section\")") end
|
||||
if not pluginSection and MC.InternalOptions[section] then error(format("Section name could not be \"%s\". This name is reserved for internal setting"), section) end
|
||||
if pluginSection and MC.InternalOptions[pluginSection][section] then error(format("Section name for plugin group \"%s\" could not be \"%s\". This name is reserved for internal setting"), pluginSection, section) end
|
||||
|
||||
local module = pluginSection and E.global.profileCopy[pluginSection][section] or E.global.profileCopy[section]
|
||||
if not module then error(format("Provided section name \"%s\" does not have a template for profile copy.", section)) end
|
||||
--Making sure tables actually exist
|
||||
if not ElvDB.profiles[E.global.profileCopy.selected][section] then ElvDB.profiles[E.global.profileCopy.selected][section] = {} end
|
||||
if not E.db[section] then E.db[section] = {} end
|
||||
--Starting digging through the settings
|
||||
local CopyFrom = pluginSection and E.db[pluginSection][section] or E.db[section]
|
||||
local CopyTo = pluginSection and ElvDB.profiles[E.global.profileCopy.selected][pluginSection][section] or ElvDB.profiles[E.global.profileCopy.selected][section]
|
||||
local CopyDefault = pluginSection and P[pluginSection][section] or P[section]
|
||||
if type(module) == "table" and next(module) then --This module is not an empty table
|
||||
MC:CopyTable(CopyFrom, CopyTo, CopyDefault, module)
|
||||
elseif type(module) == "boolean" then --Copy over entire section of profile subgroup
|
||||
E:CopyTable(CopyTo, CopyDefault)
|
||||
E:CopyTable(CopyTo, CopyFrom)
|
||||
else
|
||||
error(format("Provided section name \"%s\" does not have a valid copy template.", section))
|
||||
end
|
||||
end
|
||||
|
||||
function MC:CopyMovers(mode)
|
||||
if not E.db.movers then E.db.movers = {} end --Nothing was moved in cutrrent profile
|
||||
if not ElvDB.profiles[E.global.profileCopy.selected].movers then ElvDB.profiles[E.global.profileCopy.selected].movers = {} end --Nothing was moved in selected profile
|
||||
local CopyFrom, CopyTo
|
||||
if mode == "export" then
|
||||
CopyFrom, CopyTo = E.db.movers, ElvDB.profiles[E.global.profileCopy.selected].movers
|
||||
else
|
||||
CopyFrom, CopyTo = ElvDB.profiles[E.global.profileCopy.selected].movers or {}, E.db.movers
|
||||
end
|
||||
|
||||
for moverName in pairs(E.CreatedMovers) do
|
||||
if E.global.profileCopy.movers[moverName] then
|
||||
CopyTo[moverName] = CopyFrom[moverName]
|
||||
end
|
||||
end
|
||||
E:SetMoversPositions()
|
||||
end
|
||||
|
||||
function MC:Initialize()
|
||||
self.Initialized = true
|
||||
end
|
||||
|
||||
local function InitializeCallback()
|
||||
MC:Initialize()
|
||||
end
|
||||
|
||||
E:RegisterModule(MC:GetName(), InitializeCallback)
|
||||
@@ -0,0 +1,527 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local Sticky = E.Libs.SimpleSticky
|
||||
|
||||
--Lua functions
|
||||
local _G = _G
|
||||
local type, unpack, pairs, error = type, unpack, pairs, error
|
||||
local format, split, find = format, strsplit, strfind
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local InCombatLockdown = InCombatLockdown
|
||||
local IsControlKeyDown = IsControlKeyDown
|
||||
local IsShiftKeyDown = IsShiftKeyDown
|
||||
local ERR_NOT_IN_COMBAT = ERR_NOT_IN_COMBAT
|
||||
|
||||
E.CreatedMovers = {}
|
||||
E.DisabledMovers = {}
|
||||
|
||||
local function SizeChanged(frame)
|
||||
if InCombatLockdown() then return end
|
||||
|
||||
if frame.dirtyWidth and frame.dirtyHeight then
|
||||
frame.mover:Size(frame.dirtyWidth, frame.dirtyHeight)
|
||||
else
|
||||
frame.mover:Size(frame:GetSize())
|
||||
end
|
||||
end
|
||||
|
||||
local function GetPoint(obj)
|
||||
local point, anchor, secondaryPoint, x, y = obj:GetPoint()
|
||||
if not anchor then anchor = E.UIParent end
|
||||
|
||||
return format("%s,%s,%s,%d,%d", point, anchor:GetName(), secondaryPoint, E:Round(x), E:Round(y))
|
||||
end
|
||||
|
||||
local function UpdateCoords(self)
|
||||
local mover = self.child
|
||||
local x, y, _, nudgePoint, nudgeInversePoint = E:CalculateMoverPoints(mover)
|
||||
|
||||
local coordX, coordY = E:GetXYOffset(nudgeInversePoint, 1)
|
||||
ElvUIMoverNudgeWindow:ClearAllPoints()
|
||||
ElvUIMoverNudgeWindow:Point(nudgePoint, mover, nudgeInversePoint, coordX, coordY)
|
||||
E:UpdateNudgeFrame(mover, x, y)
|
||||
end
|
||||
|
||||
local isDragging = false
|
||||
local coordFrame = CreateFrame("Frame")
|
||||
coordFrame:SetScript("OnUpdate", UpdateCoords)
|
||||
coordFrame:Hide()
|
||||
|
||||
local function CreateMover(parent, name, text, overlay, snapOffset, postdrag, shouldDisable, configString)
|
||||
if not parent then return end --If for some reason the parent isnt loaded yet
|
||||
if E.CreatedMovers[name].Created then return end
|
||||
|
||||
if overlay == nil then overlay = true end
|
||||
local point, anchor, secondaryPoint, x, y = split(",", GetPoint(parent))
|
||||
|
||||
--Use dirtyWidth / dirtyHeight to set initial size if possible
|
||||
local width = parent.dirtyWidth or parent:GetWidth()
|
||||
local height = parent.dirtyHeight or parent:GetHeight()
|
||||
|
||||
local f = CreateFrame("Button", name, E.UIParent)
|
||||
f:SetClampedToScreen(true)
|
||||
f:RegisterForDrag("LeftButton", "RightButton")
|
||||
f:EnableMouseWheel(true)
|
||||
f:SetMovable(true)
|
||||
f:Width(width)
|
||||
f:Height(height)
|
||||
f:SetTemplate("Transparent", nil, nil, true)
|
||||
f:Hide()
|
||||
f.parent = parent
|
||||
f.name = name
|
||||
f.textString = text
|
||||
f.postdrag = postdrag
|
||||
f.overlay = overlay
|
||||
f.snapOffset = snapOffset or -2
|
||||
f.shouldDisable = shouldDisable
|
||||
f.configString = configString
|
||||
|
||||
f:SetFrameLevel(parent:GetFrameLevel() + 1)
|
||||
if overlay == true then
|
||||
f:SetFrameStrata("DIALOG")
|
||||
else
|
||||
f:SetFrameStrata("BACKGROUND")
|
||||
end
|
||||
|
||||
E.CreatedMovers[name].mover = f
|
||||
E.snapBars[#E.snapBars + 1] = f
|
||||
|
||||
local fs = f:CreateFontString(nil, "OVERLAY")
|
||||
fs:FontTemplate()
|
||||
fs:SetJustifyH("CENTER")
|
||||
fs:Point("CENTER")
|
||||
fs:SetText(text or name)
|
||||
fs:SetTextColor(unpack(E.media.rgbvaluecolor))
|
||||
f:SetFontString(fs)
|
||||
f.text = fs
|
||||
|
||||
if E.db.movers and E.db.movers[name] then
|
||||
if type(E.db.movers[name]) == "table" then
|
||||
f:Point(E.db.movers[name].p, E.UIParent, E.db.movers[name].p2, E.db.movers[name].p3, E.db.movers[name].p4)
|
||||
E.db.movers[name] = GetPoint(f)
|
||||
f:ClearAllPoints()
|
||||
end
|
||||
|
||||
--Backward compatibility
|
||||
local delim
|
||||
local anchorString = E.db.movers[name]
|
||||
if find(anchorString, "\031") then
|
||||
delim = "\031"
|
||||
elseif find(anchorString, ",") then
|
||||
delim = ","
|
||||
end
|
||||
|
||||
local point1, anchor1, secondaryPoint1, x1, y1 = split(delim, anchorString)
|
||||
f:Point(point1, anchor1, secondaryPoint1, x1, y1)
|
||||
f.anchor = anchor
|
||||
else
|
||||
f:Point(point, anchor, secondaryPoint, x, y)
|
||||
end
|
||||
|
||||
local function OnDragStart(self)
|
||||
if InCombatLockdown() then E:Print(ERR_NOT_IN_COMBAT) return end
|
||||
|
||||
if E.db.general.stickyFrames then
|
||||
Sticky:StartMoving(self, E.snapBars, f.snapOffset, f.snapOffset, f.snapOffset, f.snapOffset)
|
||||
else
|
||||
self:StartMoving()
|
||||
end
|
||||
|
||||
coordFrame.child = self
|
||||
coordFrame:Show()
|
||||
isDragging = true
|
||||
end
|
||||
|
||||
local function OnDragStop(self)
|
||||
if InCombatLockdown() then E:Print(ERR_NOT_IN_COMBAT) return end
|
||||
isDragging = false
|
||||
if E.db.general.stickyFrames then
|
||||
Sticky:StopMoving(self)
|
||||
else
|
||||
self:StopMovingOrSizing()
|
||||
end
|
||||
|
||||
local x2, y2, point2 = E:CalculateMoverPoints(self)
|
||||
self:ClearAllPoints()
|
||||
local overridePoint
|
||||
if self.positionOverride then
|
||||
if self.positionOverride == "BOTTOM" or self.positionOverride == "TOP" then
|
||||
overridePoint = "BOTTOM"
|
||||
else
|
||||
overridePoint = "BOTTOMLEFT"
|
||||
end
|
||||
end
|
||||
|
||||
self:Point(self.positionOverride or point2, E.UIParent, overridePoint and overridePoint or point2, x2, y2)
|
||||
if self.positionOverride then
|
||||
self.parent:ClearAllPoints()
|
||||
self.parent:Point(self.positionOverride, self, self.positionOverride)
|
||||
end
|
||||
|
||||
E:SaveMoverPosition(name)
|
||||
|
||||
if ElvUIMoverNudgeWindow then
|
||||
E:UpdateNudgeFrame(self, x, y)
|
||||
end
|
||||
|
||||
coordFrame.child = nil
|
||||
coordFrame:Hide()
|
||||
|
||||
if postdrag ~= nil and (type(postdrag) == "function") then
|
||||
postdrag(self, E:GetScreenQuadrant(self))
|
||||
end
|
||||
|
||||
self:SetUserPlaced(false)
|
||||
end
|
||||
|
||||
local function OnEnter(self)
|
||||
if isDragging then return end
|
||||
|
||||
self.text:SetTextColor(1, 1, 1)
|
||||
E.AssignFrameToNudge(self)
|
||||
coordFrame.child = self
|
||||
coordFrame:GetScript("OnUpdate")(coordFrame)
|
||||
end
|
||||
|
||||
local function OnMouseDown(self, button)
|
||||
if button == "LeftButton" and not isDragging then
|
||||
if ElvUIMoverNudgeWindow:IsShown() then
|
||||
ElvUIMoverNudgeWindow:Hide()
|
||||
else
|
||||
ElvUIMoverNudgeWindow:Show()
|
||||
end
|
||||
elseif button == "RightButton" then
|
||||
isDragging = false
|
||||
if E.db.general.stickyFrames then
|
||||
Sticky:StopMoving(self)
|
||||
else
|
||||
self:StopMovingOrSizing()
|
||||
end
|
||||
|
||||
--Allow resetting of anchor by Ctrl+RightClick
|
||||
if IsControlKeyDown() and self.textString then
|
||||
E:ResetMovers(self.textString)
|
||||
elseif IsShiftKeyDown() then --Allow hiding a mover temporarily
|
||||
self:Hide()
|
||||
elseif self.configString then --OpenConfig
|
||||
E:ToggleOptionsUI(self.configString)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function OnLeave(self)
|
||||
if isDragging then return end
|
||||
self.text:SetTextColor(unpack(E.media.rgbvaluecolor))
|
||||
end
|
||||
|
||||
local function OnShow(self)
|
||||
self:SetBackdropBorderColor(unpack(E.media.rgbvaluecolor))
|
||||
end
|
||||
|
||||
local function OnMouseWheel(_, delta)
|
||||
if IsShiftKeyDown() then
|
||||
E:NudgeMover(delta)
|
||||
else
|
||||
E:NudgeMover(nil, delta)
|
||||
end
|
||||
end
|
||||
|
||||
f:SetScript("OnDragStart", OnDragStart)
|
||||
f:SetScript("OnMouseUp", E.AssignFrameToNudge)
|
||||
f:SetScript("OnDragStop", OnDragStop)
|
||||
f:SetScript("OnEnter", OnEnter)
|
||||
f:SetScript("OnMouseDown", OnMouseDown)
|
||||
f:SetScript("OnLeave", OnLeave)
|
||||
f:SetScript("OnShow", OnShow)
|
||||
f:SetScript("OnMouseWheel", OnMouseWheel)
|
||||
|
||||
parent:SetScript("OnSizeChanged", SizeChanged)
|
||||
parent.mover = f
|
||||
|
||||
parent:ClearAllPoints()
|
||||
parent:Point(point, f, 0, 0)
|
||||
|
||||
if postdrag ~= nil and type(postdrag) == "function" then
|
||||
f:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
f:SetScript("OnEvent", function(self)
|
||||
postdrag(f, E:GetScreenQuadrant(f))
|
||||
self:UnregisterAllEvents()
|
||||
end)
|
||||
end
|
||||
|
||||
E.CreatedMovers[name].Created = true
|
||||
end
|
||||
|
||||
function E:CalculateMoverPoints(mover, nudgeX, nudgeY)
|
||||
local screenWidth, screenHeight, screenCenter = E.UIParent:GetRight(), E.UIParent:GetTop(), E.UIParent:GetCenter()
|
||||
local x, y = mover:GetCenter()
|
||||
|
||||
local LEFT = screenWidth / 3
|
||||
local RIGHT = screenWidth * 2 / 3
|
||||
local TOP = screenHeight / 2
|
||||
local point, nudgePoint, nudgeInversePoint
|
||||
|
||||
if y >= TOP then
|
||||
point = "TOP"
|
||||
nudgePoint = "TOP"
|
||||
nudgeInversePoint = "BOTTOM"
|
||||
y = -(screenHeight - mover:GetTop())
|
||||
else
|
||||
point = "BOTTOM"
|
||||
nudgePoint = "BOTTOM"
|
||||
nudgeInversePoint = "TOP"
|
||||
y = mover:GetBottom()
|
||||
end
|
||||
|
||||
if x >= RIGHT then
|
||||
point = point.."RIGHT"
|
||||
nudgePoint = "RIGHT"
|
||||
nudgeInversePoint = "LEFT"
|
||||
x = mover:GetRight() - screenWidth
|
||||
elseif x <= LEFT then
|
||||
point = point.."LEFT"
|
||||
nudgePoint = "LEFT"
|
||||
nudgeInversePoint = "RIGHT"
|
||||
x = mover:GetLeft()
|
||||
else
|
||||
x = x - screenCenter
|
||||
end
|
||||
|
||||
if mover.positionOverride and (E.diffGetLeft and E.diffGetRight and E.diffGetTop and E.diffGetBottom) then
|
||||
if mover.positionOverride == "TOPLEFT" then
|
||||
x = mover:GetLeft() - E.diffGetLeft
|
||||
y = mover:GetTop() - E.diffGetTop
|
||||
elseif mover.positionOverride == "TOPRIGHT" then
|
||||
x = mover:GetRight() - E.diffGetRight
|
||||
y = mover:GetTop() - E.diffGetTop
|
||||
elseif mover.positionOverride == "BOTTOMLEFT" then
|
||||
x = mover:GetLeft() - E.diffGetLeft
|
||||
y = mover:GetBottom() - E.diffGetBottom
|
||||
elseif mover.positionOverride == "BOTTOMRIGHT" then
|
||||
x = mover:GetRight() - E.diffGetRight
|
||||
y = mover:GetBottom() - E.diffGetBottom
|
||||
elseif mover.positionOverride == "BOTTOM" then
|
||||
x = mover:GetCenter() - screenCenter
|
||||
y = mover:GetBottom() - E.diffGetBottom
|
||||
elseif mover.positionOverride == "TOP" then
|
||||
x = mover:GetCenter() - screenCenter
|
||||
y = mover:GetTop() - E.diffGetTop
|
||||
end
|
||||
end
|
||||
|
||||
--Update coordinates if nudged
|
||||
x = x + (nudgeX or 0)
|
||||
y = y + (nudgeY or 0)
|
||||
|
||||
return x, y, point, nudgePoint, nudgeInversePoint
|
||||
end
|
||||
|
||||
function E:UpdatePositionOverride(name)
|
||||
local frame = _G[name]
|
||||
local OnDragStop = frame and frame.GetScript and frame:GetScript("OnDragStop")
|
||||
if OnDragStop then OnDragStop(frame) end
|
||||
end
|
||||
|
||||
function E:HasMoverBeenMoved(name)
|
||||
if E.db.movers and E.db.movers[name] then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function E:SaveMoverPosition(name)
|
||||
if not _G[name] then return end
|
||||
if not E.db.movers then E.db.movers = {} end
|
||||
|
||||
local mover = _G[name]
|
||||
local _, anchor = mover:GetPoint()
|
||||
mover.anchor = anchor:GetName()
|
||||
|
||||
E.db.movers[name] = GetPoint(mover)
|
||||
end
|
||||
|
||||
function E:SetMoverSnapOffset(name, offset)
|
||||
if not _G[name] or not E.CreatedMovers[name] then return end
|
||||
E.CreatedMovers[name].mover.snapOffset = offset or -2
|
||||
E.CreatedMovers[name].snapoffset = offset or -2
|
||||
end
|
||||
|
||||
function E:SaveMoverDefaultPosition(name)
|
||||
if not _G[name] then return end
|
||||
|
||||
E.CreatedMovers[name].point = GetPoint(_G[name])
|
||||
E.CreatedMovers[name].postdrag(_G[name], E:GetScreenQuadrant(_G[name]))
|
||||
end
|
||||
|
||||
function E:CreateMover(parent, name, text, overlay, snapoffset, postdrag, moverTypes, shouldDisable, configString)
|
||||
if not moverTypes then moverTypes = "ALL,GENERAL" end
|
||||
|
||||
if E.CreatedMovers[name] == nil then
|
||||
E.CreatedMovers[name] = {}
|
||||
E.CreatedMovers[name].parent = parent
|
||||
E.CreatedMovers[name].text = text
|
||||
E.CreatedMovers[name].overlay = overlay
|
||||
E.CreatedMovers[name].postdrag = postdrag
|
||||
E.CreatedMovers[name].snapoffset = snapoffset
|
||||
E.CreatedMovers[name].point = GetPoint(parent)
|
||||
E.CreatedMovers[name].shouldDisable = shouldDisable
|
||||
E.CreatedMovers[name].configString = configString
|
||||
|
||||
E.CreatedMovers[name].type = {}
|
||||
local types = {split(",", moverTypes)}
|
||||
for i = 1, #types do
|
||||
local moverType = types[i]
|
||||
E.CreatedMovers[name].type[moverType] = true
|
||||
end
|
||||
end
|
||||
|
||||
CreateMover(parent, name, text, overlay, snapoffset, postdrag, shouldDisable, configString)
|
||||
end
|
||||
|
||||
function E:ToggleMovers(show, moverType)
|
||||
self.configMode = show
|
||||
|
||||
for name in pairs(E.CreatedMovers) do
|
||||
if not show then
|
||||
_G[name]:Hide()
|
||||
else
|
||||
if E.CreatedMovers[name].type[moverType] then
|
||||
_G[name]:Show()
|
||||
else
|
||||
_G[name]:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:DisableMover(name)
|
||||
if self.DisabledMovers[name] then return end
|
||||
|
||||
if not self.CreatedMovers[name] then
|
||||
error("mover doesn't exist")
|
||||
end
|
||||
|
||||
self.DisabledMovers[name] = {}
|
||||
for x, y in pairs(self.CreatedMovers[name]) do
|
||||
self.DisabledMovers[name][x] = y
|
||||
end
|
||||
|
||||
if self.configMode then
|
||||
_G[name]:Hide()
|
||||
end
|
||||
|
||||
self.CreatedMovers[name] = nil
|
||||
end
|
||||
|
||||
function E:EnableMover(name)
|
||||
if self.CreatedMovers[name] then return end
|
||||
|
||||
if not self.DisabledMovers[name] then
|
||||
error("mover doesn't exist")
|
||||
end
|
||||
|
||||
self.CreatedMovers[name] = {}
|
||||
for x, y in pairs(self.DisabledMovers[name]) do
|
||||
self.CreatedMovers[name][x] = y
|
||||
end
|
||||
|
||||
--Make sure we add anchor information from a potential profile switch
|
||||
--Commented out, as it created an issue with trying to reset a mover after having used EnableMover on it. Not sure if this code is even needed anymore.
|
||||
-- if E.db.movers and E.db.movers[name] and type(E.db.movers[name]) == 'string' then
|
||||
-- self.CreatedMovers[name].point = E.db.movers[name]
|
||||
-- end
|
||||
|
||||
if self.configMode then
|
||||
_G[name]:Show()
|
||||
end
|
||||
|
||||
self.DisabledMovers[name] = nil
|
||||
end
|
||||
|
||||
function E:ResetMovers(arg)
|
||||
if arg == "" or arg == nil then
|
||||
for name in pairs(E.CreatedMovers) do
|
||||
local f = _G[name]
|
||||
local point, anchor, secondaryPoint, x, y = split(",", E.CreatedMovers[name].point)
|
||||
f:ClearAllPoints()
|
||||
f:Point(point, anchor, secondaryPoint, x, y)
|
||||
|
||||
for key, value in pairs(E.CreatedMovers[name]) do
|
||||
if key == "postdrag" and type(value) == "function" then
|
||||
value(f, E:GetScreenQuadrant(f))
|
||||
end
|
||||
end
|
||||
end
|
||||
self.db.movers = nil
|
||||
else
|
||||
for name in pairs(E.CreatedMovers) do
|
||||
for key, value in pairs(E.CreatedMovers[name]) do
|
||||
if key == "text" then
|
||||
if arg == value then
|
||||
local f = _G[name]
|
||||
local point, anchor, secondaryPoint, x, y = split(",", E.CreatedMovers[name].point)
|
||||
f:ClearAllPoints()
|
||||
f:Point(point, anchor, secondaryPoint, x, y)
|
||||
|
||||
if self.db.movers then
|
||||
self.db.movers[name] = nil
|
||||
end
|
||||
|
||||
if E.CreatedMovers[name].postdrag ~= nil and type(E.CreatedMovers[name].postdrag) == "function" then
|
||||
E.CreatedMovers[name].postdrag(f, E:GetScreenQuadrant(f))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Profile Change
|
||||
function E:SetMoversPositions()
|
||||
--E:SetMoversPositions() is the first function called in E:UpdateAll().
|
||||
--Because of that, we can allow ourselves to re-enable all disabled movers here,
|
||||
--as the subsequent updates to these elements will disable them again if needed.
|
||||
for name in pairs(E.DisabledMovers) do
|
||||
local shouldDisable = ((E.DisabledMovers[name].shouldDisable and E.DisabledMovers[name].shouldDisable()) or false)
|
||||
if not shouldDisable then
|
||||
E:EnableMover(name)
|
||||
end
|
||||
end
|
||||
|
||||
for name in pairs(E.CreatedMovers) do
|
||||
local f = _G[name]
|
||||
local point, anchor, secondaryPoint, x, y
|
||||
if E.db.movers and E.db.movers[name] and type(E.db.movers[name]) == "string" then
|
||||
--Backward compatibility
|
||||
local delim
|
||||
local anchorString = E.db.movers[name]
|
||||
if find(anchorString, "\031") then
|
||||
delim = "\031"
|
||||
elseif find(anchorString, ",") then
|
||||
delim = ","
|
||||
end
|
||||
point, anchor, secondaryPoint, x, y = split(delim, anchorString)
|
||||
f:ClearAllPoints()
|
||||
f:Point(point, anchor, secondaryPoint, x, y)
|
||||
elseif f then
|
||||
point, anchor, secondaryPoint, x, y = split(",", E.CreatedMovers[name].point)
|
||||
f:ClearAllPoints()
|
||||
f:Point(point, anchor, secondaryPoint, x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function E:SetMoversClampedToScreen(value)
|
||||
for name in pairs(E.CreatedMovers) do
|
||||
_G[name]:SetClampedToScreen(value)
|
||||
end
|
||||
end
|
||||
|
||||
--Called from core.lua
|
||||
function E:LoadMovers()
|
||||
for name, t in pairs(E.CreatedMovers) do
|
||||
CreateMover(t.parent, name, t.text, t.overlay, t.snapoffset, t.postdrag, t.shouldDisable, t.configString)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,91 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
|
||||
--Lua functions
|
||||
local min, max, abs, floor = min, max, abs, floor
|
||||
--WoW API / Variables
|
||||
local UIParent = UIParent
|
||||
|
||||
function E:IsEyefinity(width, height)
|
||||
if E.global.general.eyefinity and width >= 3840 then
|
||||
--HQ resolution
|
||||
if width >= 9840 then return 3280 end --WQSXGA
|
||||
if width >= 7680 and width < 9840 then return 2560 end --WQXGA
|
||||
if width >= 5760 and width < 7680 then return 1920 end --WUXGA & HDTV
|
||||
if width >= 5040 and width < 5760 then return 1680 end --WSXGA+
|
||||
|
||||
--adding height condition here to be sure it work with bezel compensation because WSXGA+ and UXGA/HD+ got approx same width
|
||||
if width >= 4800 and width < 5760 and height == 900 then return 1600 end --UXGA & HD+
|
||||
|
||||
--low resolution screen
|
||||
if width >= 4320 and width < 4800 then return 1440 end --WSXGA
|
||||
if width >= 4080 and width < 4320 then return 1360 end --WXGA
|
||||
if width >= 3840 and width < 4080 then return 1224 end --SXGA & SXGA (UVGA) & WXGA & HDTV
|
||||
end
|
||||
end
|
||||
|
||||
function E:UIScale(init)
|
||||
local scale = E.global.general.UIScale
|
||||
if init then --E.OnInitialize
|
||||
--Set variables for pixel scaling
|
||||
local pixel, ratio = 1, 768 / E.screenheight
|
||||
E.mult = (pixel / scale) - ((pixel - ratio) / scale)
|
||||
E.Spacing = (E.PixelMode and 0) or E.mult
|
||||
E.Border = ((not E.twoPixelsPlease) and E.PixelMode and E.mult) or E.mult*2
|
||||
else --E.Initialize
|
||||
UIParent:SetScale(scale)
|
||||
|
||||
--Check if we are using `E.eyefinity`
|
||||
local width, height = E.screenwidth, E.screenheight
|
||||
E.eyefinity = E:IsEyefinity(width, height)
|
||||
|
||||
--Resize E.UIParent if Eyefinity is on.
|
||||
local testingEyefinity = false
|
||||
if testingEyefinity then
|
||||
--Eyefinity Test: Resize the E.UIParent to be smaller than it should be, all objects inside should relocate.
|
||||
--Dragging moveable frames outside the box and reloading the UI ensures that they are saving position correctly.
|
||||
local uiWidth, uiHeight = UIParent:GetSize()
|
||||
width, height = uiWidth - 250, uiHeight - 250
|
||||
elseif E.eyefinity then
|
||||
--find a new width value of E.UIParent for screen #1.
|
||||
local uiHeight = UIParent:GetHeight()
|
||||
width, height = E.eyefinity / (height / uiHeight), uiHeight
|
||||
else
|
||||
width, height = UIParent:GetSize()
|
||||
end
|
||||
|
||||
E.UIParent:SetSize(width, height)
|
||||
E.UIParent.origHeight = E.UIParent:GetHeight()
|
||||
|
||||
--Calculate potential coordinate differences
|
||||
E.diffGetLeft = E:Round(abs(UIParent:GetLeft() - E.UIParent:GetLeft()))
|
||||
E.diffGetRight = E:Round(abs(UIParent:GetRight() - E.UIParent:GetRight()))
|
||||
E.diffGetBottom = E:Round(abs(UIParent:GetBottom() - E.UIParent:GetBottom()))
|
||||
E.diffGetTop = E:Round(abs(UIParent:GetTop() - E.UIParent:GetTop()))
|
||||
end
|
||||
end
|
||||
|
||||
function E:PixelBestSize()
|
||||
return max(0.4, min(1.15, 768 / E.screenheight))
|
||||
end
|
||||
|
||||
function E:PixelScaleChanged(event, skip)
|
||||
E:UIScale(true) -- repopulate variables
|
||||
E:UIScale() -- setup the scale
|
||||
|
||||
E:UpdateConfigSize(true) -- reposition config
|
||||
|
||||
if skip or E.global.general.ignoreScalePopup then return end
|
||||
|
||||
if event == "UPDATE_FLOATING_CHAT_WINDOWS" then return end
|
||||
|
||||
if event == "UISCALE_CHANGE" then
|
||||
E:Delay(0.5, E.StaticPopup_Show, E, event)
|
||||
else
|
||||
E:StaticPopup_Show("UISCALE_CHANGE")
|
||||
end
|
||||
end
|
||||
|
||||
function E:Scale(x)
|
||||
local mult = E.mult
|
||||
return mult * floor(x / mult + 0.5)
|
||||
end
|
||||
@@ -0,0 +1,458 @@
|
||||
--Plugins pass their info using the table like:
|
||||
--[[
|
||||
addon = {
|
||||
Title = "Your Own Title",
|
||||
Name = "AddOnName",
|
||||
tutorialImage = "TexturePath",
|
||||
Pages = {
|
||||
[1] = function1,
|
||||
[2] = function2,
|
||||
[3] = function3,
|
||||
},
|
||||
StepTitles = {
|
||||
[1] = "Title 1",
|
||||
[2] = "Title 2",
|
||||
[3] = "Title 3",
|
||||
},
|
||||
StepTitlesColor = {r,g,b},
|
||||
StepTitlesColorSelected = {r,g,b},
|
||||
StepTitleWidth = 140,
|
||||
StepTitleButtonWidth = 130,
|
||||
StepTitleTextJustification = "CENTER",
|
||||
}
|
||||
E:GetModule("PluginInstaller"):Queue(addon)
|
||||
|
||||
Title is wat displayed on top of the window. By default it's ""ElvUI Plugin Installation""
|
||||
Name is how your installation will be showin in "pending list", Default is "Unknown"
|
||||
tutorialImage is a path to your own texture to use in frame. if not specified, then it will use ElvUI's one
|
||||
Pages is a table to set up pages of your install where numbers are representing actual pages' order and function is what previously was used to set layout. For example
|
||||
function function1()
|
||||
PluginInstallFrame.SubTitle:SetText("Title Text")
|
||||
PluginInstallFrame.Desc1:SetText("Desc 1 Tet")
|
||||
PluginInstallFrame.Desc2:SetText("Desc 2 Tet")
|
||||
PluginInstallFrame.Desc3:SetText("Desc 3 Tet")
|
||||
|
||||
PluginInstallFrame.Option1:Show()
|
||||
PluginInstallFrame.Option1:SetScript("OnClick", function() <Do Some Stuff> end)
|
||||
PluginInstallFrame.Option1:SetText("Text 1")
|
||||
|
||||
PluginInstallFrame.Option2:Show()
|
||||
PluginInstallFrame.Option2:SetScript("OnClick", function() <Do Some Other Stuff> end)
|
||||
PluginInstallFrame.Option2:SetText("Text 2")
|
||||
end
|
||||
StepTitles - a table to specify "titles" for your install steps. If specified and number of lines here = number of pages then you'll get an additional frame to the right of main frame
|
||||
with a list of steps (current one being highlighted), clicking on those will open respective step. BenikUI style of doing stuff.
|
||||
StepTitlesColor - a table with color values to color "titles" when they are not active
|
||||
StepTitlesColorSelected - a table with color values to color "titles" when they are active
|
||||
StepTitleWidth - Width of the steps frame on the right side
|
||||
StepTitleButtonWidth - Width of each step button in the steps frame
|
||||
StepTitleTextJustification - The justification of the text on each step button ("LEFT", "RIGHT", "CENTER"). Default: "CENTER"
|
||||
]]
|
||||
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB, Localize Underscore
|
||||
local PI = E:GetModule("PluginInstaller")
|
||||
local S = E:GetModule("Skins")
|
||||
|
||||
--Lua functions
|
||||
local pairs, unpack = pairs, unpack
|
||||
local tinsert, tremove = tinsert, tremove
|
||||
local format = string.format
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local PlaySoundFile = PlaySoundFile
|
||||
local UIFrameFadeOut = UIFrameFadeOut
|
||||
local CONTINUE, PREVIOUS, UNKNOWN = CONTINUE, PREVIOUS, UNKNOWN
|
||||
|
||||
--Global variables that we don't cache, list them here for the mikk's Find Globals script
|
||||
-- GLOBALS: PluginInstallFrame
|
||||
|
||||
--Installation Functions
|
||||
PI.Installs = {}
|
||||
local f
|
||||
local BUTTON_HEIGHT = 20
|
||||
|
||||
local function ResetAll()
|
||||
f.Next:Disable()
|
||||
f.Prev:Disable()
|
||||
f.Option1:Hide()
|
||||
f.Option1:SetScript("OnClick", nil)
|
||||
f.Option1:SetText("")
|
||||
f.Option2:Hide()
|
||||
f.Option2:SetScript("OnClick", nil)
|
||||
f.Option2:SetText("")
|
||||
f.Option3:Hide()
|
||||
f.Option3:SetScript("OnClick", nil)
|
||||
f.Option3:SetText("")
|
||||
f.Option4:Hide()
|
||||
f.Option4:SetScript("OnClick", nil)
|
||||
f.Option4:SetText("")
|
||||
f.SubTitle:SetText("")
|
||||
f.Desc1:SetText("")
|
||||
f.Desc2:SetText("")
|
||||
f.Desc3:SetText("")
|
||||
f.Desc4:SetText("")
|
||||
f:Size(550, 400)
|
||||
if f.StepTitles then
|
||||
for i = 1, #f.side.Lines do f.side.Lines[i].text:SetText("") end
|
||||
end
|
||||
end
|
||||
|
||||
local function SetPage(PageNum, PrevPage)
|
||||
f.CurrentPage = PageNum
|
||||
f.PrevPage = PrevPage
|
||||
ResetAll()
|
||||
f.Status.anim.progress:SetChange(PageNum)
|
||||
f.Status.anim.progress:Play()
|
||||
|
||||
local r, g, b = E:ColorGradient(f.CurrentPage / f.MaxPage, 1, 0, 0, 1, 1, 0, 0, 1, 0)
|
||||
f.Status:SetStatusBarColor(r, g, b)
|
||||
|
||||
if PageNum == f.MaxPage then
|
||||
f.Next:Disable()
|
||||
else
|
||||
f.Next:Enable()
|
||||
end
|
||||
|
||||
if PageNum == 1 then
|
||||
f.Prev:Disable()
|
||||
else
|
||||
f.Prev:Enable()
|
||||
end
|
||||
|
||||
f.Pages[f.CurrentPage]()
|
||||
f.Status.text:SetFormattedText("%d / %d", f.CurrentPage, f.MaxPage)
|
||||
if f.StepTitles then
|
||||
for i = 1, #f.side.Lines do
|
||||
local button = f.side.Lines[i]
|
||||
local color
|
||||
button.text:SetText(f.StepTitles[i])
|
||||
if i == f.CurrentPage then
|
||||
color = f.StepTitlesColorSelected or {0.09, 0.52, 0.82}
|
||||
else
|
||||
color = f.StepTitlesColor or {1, 1, 1}
|
||||
end
|
||||
button.text:SetTextColor(color[1] or color.r, color[2] or color.g, color[3] or color.b)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function NextPage()
|
||||
if f.CurrentPage ~= f.MaxPage then
|
||||
f.CurrentPage = f.CurrentPage + 1
|
||||
SetPage(f.CurrentPage, f.CurrentPage - 1)
|
||||
end
|
||||
end
|
||||
|
||||
local function PreviousPage()
|
||||
if f.CurrentPage ~= 1 then
|
||||
f.CurrentPage = f.CurrentPage - 1
|
||||
SetPage(f.CurrentPage, f.CurrentPage + 1)
|
||||
end
|
||||
end
|
||||
|
||||
function PI:CreateStepComplete()
|
||||
local imsg = CreateFrame("Frame", "PluginInstallStepComplete", E.UIParent)
|
||||
imsg:Size(418, 72)
|
||||
imsg:Point("TOP", 0, -190)
|
||||
imsg:Hide()
|
||||
imsg:SetScript("OnShow", function(frame)
|
||||
if frame.message then
|
||||
PlaySoundFile([[Sound\Interface\LevelUp.wav]])
|
||||
frame.text:SetText(frame.message)
|
||||
UIFrameFadeOut(frame, 3.5, 1, 0)
|
||||
E:Delay(4, frame.Hide, frame)
|
||||
frame.message = nil
|
||||
else
|
||||
frame:Hide()
|
||||
end
|
||||
end)
|
||||
|
||||
imsg.firstShow = false
|
||||
|
||||
imsg.bg = imsg:CreateTexture(nil, "BACKGROUND")
|
||||
imsg.bg:SetTexture([[Interface\LevelUp\LevelUpTex]])
|
||||
imsg.bg:SetPoint("BOTTOM")
|
||||
imsg.bg:Size(326, 103)
|
||||
imsg.bg:SetTexCoord(0.00195313, 0.63867188, 0.03710938, 0.23828125)
|
||||
imsg.bg:SetVertexColor(1, 1, 1, 0.6)
|
||||
|
||||
imsg.lineTop = imsg:CreateTexture(nil, "BACKGROUND")
|
||||
imsg.lineTop:SetDrawLayer("BACKGROUND", 2)
|
||||
imsg.lineTop:SetTexture([[Interface\LevelUp\LevelUpTex]])
|
||||
imsg.lineTop:SetPoint("TOP")
|
||||
imsg.lineTop:Size(418, 7)
|
||||
imsg.lineTop:SetTexCoord(0.00195313, 0.81835938, 0.01953125, 0.03320313)
|
||||
|
||||
imsg.lineBottom = imsg:CreateTexture(nil, "BACKGROUND")
|
||||
imsg.lineBottom:SetDrawLayer("BACKGROUND", 2)
|
||||
imsg.lineBottom:SetTexture([[Interface\LevelUp\LevelUpTex]])
|
||||
imsg.lineBottom:SetPoint("BOTTOM")
|
||||
imsg.lineBottom:Size(418, 7)
|
||||
imsg.lineBottom:SetTexCoord(0.00195313, 0.81835938, 0.01953125, 0.03320313)
|
||||
|
||||
imsg.text = imsg:CreateFontString(nil, "ARTWORK")
|
||||
imsg.text:FontTemplate(E.media.normFont, 32, "OUTLINE")
|
||||
imsg.text:Point("BOTTOM", 0, 12)
|
||||
imsg.text:SetTextColor(1, 0.82, 0)
|
||||
imsg.text:SetJustifyH("CENTER")
|
||||
end
|
||||
|
||||
function PI:CreateFrame()
|
||||
f = CreateFrame("Button", "PluginInstallFrame", E.UIParent)
|
||||
f.SetPage = SetPage
|
||||
f:Size(550, 400)
|
||||
f:SetTemplate("Transparent")
|
||||
f:SetPoint("CENTER")
|
||||
f:SetFrameStrata("TOOLTIP")
|
||||
|
||||
f.Title = f:CreateFontString(nil, "OVERLAY")
|
||||
f.Title:FontTemplate(nil, 17, nil)
|
||||
f.Title:Point("TOP", 0, -5)
|
||||
|
||||
f.Next = CreateFrame("Button", "PluginInstallNextButton", f, "UIPanelButtonTemplate")
|
||||
f.Next:Size(110, 25)
|
||||
f.Next:Point("BOTTOMRIGHT", -5, 5)
|
||||
f.Next:SetText(CONTINUE)
|
||||
f.Next:Disable()
|
||||
f.Next:SetScript("OnClick", NextPage)
|
||||
S:HandleButton(f.Next, true)
|
||||
|
||||
f.Prev = CreateFrame("Button", "PluginInstallPrevButton", f, "UIPanelButtonTemplate")
|
||||
f.Prev:Size(110, 25)
|
||||
f.Prev:Point("BOTTOMLEFT", 5, 5)
|
||||
f.Prev:SetText(PREVIOUS)
|
||||
f.Prev:Disable()
|
||||
f.Prev:SetScript("OnClick", PreviousPage)
|
||||
S:HandleButton(f.Prev, true)
|
||||
|
||||
f.Status = CreateFrame("StatusBar", "PluginInstallStatus", f)
|
||||
f.Status:SetFrameLevel(f.Status:GetFrameLevel() + 2)
|
||||
f.Status:CreateBackdrop("Default", true)
|
||||
f.Status:SetStatusBarTexture(E.media.normTex)
|
||||
f.Status:SetStatusBarColor(unpack(E.media.rgbvaluecolor))
|
||||
f.Status:Point("TOPLEFT", f.Prev, "TOPRIGHT", 6, -2)
|
||||
f.Status:Point("BOTTOMRIGHT", f.Next, "BOTTOMLEFT", -6, 2)
|
||||
-- Setup StatusBar Animation
|
||||
f.Status.anim = CreateAnimationGroup(f.Status)
|
||||
f.Status.anim.progress = f.Status.anim:CreateAnimation("Progress")
|
||||
f.Status.anim.progress:SetEasing("Out")
|
||||
f.Status.anim.progress:SetDuration(.3)
|
||||
|
||||
f.Status.text = f.Status:CreateFontString(nil, "OVERLAY")
|
||||
f.Status.text:FontTemplate()
|
||||
f.Status.text:SetPoint("CENTER")
|
||||
|
||||
f.Option1 = CreateFrame("Button", "PluginInstallOption1Button", f, "UIPanelButtonTemplate")
|
||||
f.Option1:Size(160, 30)
|
||||
f.Option1:Point("BOTTOM", 0, 45)
|
||||
f.Option1:SetText("")
|
||||
f.Option1:Hide()
|
||||
S:HandleButton(f.Option1, true)
|
||||
|
||||
f.Option2 = CreateFrame("Button", "PluginInstallOption2Button", f, "UIPanelButtonTemplate")
|
||||
f.Option2:Size(110, 30)
|
||||
f.Option2:Point("BOTTOMLEFT", f, "BOTTOM", 4, 45)
|
||||
f.Option2:SetText("")
|
||||
f.Option2:Hide()
|
||||
f.Option2:SetScript("OnShow", function() f.Option1:SetWidth(110) f.Option1:ClearAllPoints() f.Option1:Point("BOTTOMRIGHT", f, "BOTTOM", -4, 45) end)
|
||||
f.Option2:SetScript("OnHide", function() f.Option1:SetWidth(160) f.Option1:ClearAllPoints() f.Option1:Point("BOTTOM", 0, 45) end)
|
||||
S:HandleButton(f.Option2, true)
|
||||
|
||||
f.Option3 = CreateFrame("Button", "PluginInstallOption3Button", f, "UIPanelButtonTemplate")
|
||||
f.Option3:Size(100, 30)
|
||||
f.Option3:Point("LEFT", f.Option2, "RIGHT", 4, 0)
|
||||
f.Option3:SetText("")
|
||||
f.Option3:Hide()
|
||||
f.Option3:SetScript("OnShow", function() f.Option1:SetWidth(100) f.Option1:ClearAllPoints() f.Option1:Point("RIGHT", f.Option2, "LEFT", -4, 0) f.Option2:SetWidth(100) f.Option2:ClearAllPoints() f.Option2:Point("BOTTOM", f, "BOTTOM", 0, 45) end)
|
||||
f.Option3:SetScript("OnHide", function() f.Option1:SetWidth(160) f.Option1:ClearAllPoints() f.Option1:Point("BOTTOM", 0, 45) f.Option2:SetWidth(110) f.Option2:ClearAllPoints() f.Option2:Point("BOTTOMLEFT", f, "BOTTOM", 4, 45) end)
|
||||
S:HandleButton(f.Option3, true)
|
||||
|
||||
f.Option4 = CreateFrame("Button", "PluginInstallOption4Button", f, "UIPanelButtonTemplate")
|
||||
f.Option4:Size(100, 30)
|
||||
f.Option4:Point("LEFT", f.Option3, "RIGHT", 4, 0)
|
||||
f.Option4:SetText("")
|
||||
f.Option4:Hide()
|
||||
f.Option4:SetScript("OnShow", function()
|
||||
f.Option1:Width(100)
|
||||
f.Option2:Width(100)
|
||||
|
||||
f.Option1:ClearAllPoints()
|
||||
f.Option1:Point("RIGHT", f.Option2, "LEFT", -4, 0)
|
||||
f.Option2:ClearAllPoints()
|
||||
f.Option2:Point("BOTTOMRIGHT", f, "BOTTOM", -4, 45)
|
||||
end)
|
||||
f.Option4:SetScript("OnHide", function() f.Option1:SetWidth(160) f.Option1:ClearAllPoints() f.Option1:Point("BOTTOM", 0, 45) f.Option2:SetWidth(110) f.Option2:ClearAllPoints() f.Option2:Point("BOTTOMLEFT", f, "BOTTOM", 4, 45) end)
|
||||
S:HandleButton(f.Option4, true)
|
||||
|
||||
f.SubTitle = f:CreateFontString(nil, "OVERLAY")
|
||||
f.SubTitle:FontTemplate(nil, 15, nil)
|
||||
f.SubTitle:Point("TOP", 0, -40)
|
||||
|
||||
f.Desc1 = f:CreateFontString(nil, "OVERLAY")
|
||||
f.Desc1:FontTemplate()
|
||||
f.Desc1:Point("TOPLEFT", 20, -75)
|
||||
f.Desc1:Width(f:GetWidth() - 40)
|
||||
|
||||
f.Desc2 = f:CreateFontString(nil, "OVERLAY")
|
||||
f.Desc2:FontTemplate()
|
||||
f.Desc2:Point("TOP", f.Desc1, "BOTTOM", 0, -20)
|
||||
f.Desc2:Width(f:GetWidth() - 40)
|
||||
|
||||
f.Desc3 = f:CreateFontString(nil, "OVERLAY")
|
||||
f.Desc3:FontTemplate()
|
||||
f.Desc3:Point("TOP", f.Desc2, "BOTTOM", 0, -20)
|
||||
f.Desc3:Width(f:GetWidth() - 40)
|
||||
|
||||
f.Desc4 = f:CreateFontString(nil, "OVERLAY")
|
||||
f.Desc4:FontTemplate()
|
||||
f.Desc4:Point("TOP", f.Desc3, "BOTTOM", 0, -20)
|
||||
f.Desc4:Width(f:GetWidth() - 40)
|
||||
|
||||
local close = CreateFrame("Button", "PluginInstallCloseButton", f, "UIPanelCloseButton")
|
||||
close:SetPoint("TOPRIGHT", f, "TOPRIGHT")
|
||||
close:SetScript("OnClick", function() f:Hide() end)
|
||||
S:HandleCloseButton(close)
|
||||
|
||||
f.pending = CreateFrame("Frame", "PluginInstallPendingButton", f)
|
||||
f.pending:Size(20, 20)
|
||||
f.pending:SetPoint("TOPLEFT", f, "TOPLEFT", 8, -8)
|
||||
f.pending.tex = f.pending:CreateTexture(nil, "OVERLAY")
|
||||
f.pending.tex:Point("TOPLEFT", f.pending, "TOPLEFT", 2, -2)
|
||||
f.pending.tex:Point("BOTTOMRIGHT", f.pending, "BOTTOMRIGHT", -2, 2)
|
||||
f.pending.tex:SetTexture([[Interface\OptionsFrame\UI-OptionsFrame-NewFeatureIcon]])
|
||||
f.pending:CreateBackdrop("Transparent")
|
||||
f.pending:SetScript("OnEnter", function(self)
|
||||
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT", E.PixelMode and -7 or -9)
|
||||
GameTooltip:AddLine(L["List of installations in queue:"], 1, 1, 1)
|
||||
GameTooltip:AddLine(" ")
|
||||
for i = 1, #PI.Installs do
|
||||
GameTooltip:AddDoubleLine(format("%d. %s", i, (PI.Installs[i].Name or UNKNOWN)), i == 1 and format("|cff00FF00%s|r", L["In Progress"]) or format("|cffFF0000%s|r", L["Pending"]))
|
||||
end
|
||||
GameTooltip:Show()
|
||||
end)
|
||||
f.pending:SetScript("OnLeave", function()
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
|
||||
f.tutorialImage = f:CreateTexture("PluginInstallTutorialImage", "OVERLAY")
|
||||
f.tutorialImage:Size(256, 128)
|
||||
f.tutorialImage:Point("BOTTOM", 0, 70)
|
||||
|
||||
f.side = CreateFrame("Frame", "PluginInstallTitleFrame", f)
|
||||
f.side:SetTemplate("Transparent")
|
||||
f.side:SetPoint("TOPLEFT", f, "TOPRIGHT", E.PixelMode and 1 or 3, 0)
|
||||
f.side:SetPoint("BOTTOMLEFT", f, "BOTTOMRIGHT", E.PixelMode and 1 or 3, 0)
|
||||
f.side:Width(140)
|
||||
f.side.text = f.side:CreateFontString(nil, "OVERLAY")
|
||||
f.side.text:SetPoint("TOP", f.side, "TOP", 0, -4)
|
||||
f.side.text:FontTemplate(E.media.normFont, 18, "OUTLINE")
|
||||
f.side.text:SetText(L["Steps"])
|
||||
f.side.Lines = {} --Table to keep shown lines
|
||||
f.side:Hide()
|
||||
for i = 1, 18 do
|
||||
local button = CreateFrame("Button", nil, f)
|
||||
if i == 1 then
|
||||
button:SetPoint("TOP", f.side.text, "BOTTOM", 0, -6)
|
||||
else
|
||||
button:SetPoint("TOP", f.side.Lines[i - 1], "BOTTOM")
|
||||
end
|
||||
button:SetSize(130, BUTTON_HEIGHT)
|
||||
button.text = button:CreateFontString(nil, "OVERLAY")
|
||||
button.text:SetPoint("TOPLEFT", button, "TOPLEFT", 2, -2)
|
||||
button.text:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -2, 2)
|
||||
button.text:FontTemplate(E.media.normFont, 14, "OUTLINE")
|
||||
button:SetScript("OnClick", function() if i <= f.MaxPage then SetPage(i, f.CurrentPage) end end)
|
||||
button.text:SetText("")
|
||||
f.side.Lines[i] = button
|
||||
button:Hide()
|
||||
end
|
||||
|
||||
f:Hide()
|
||||
|
||||
f:SetScript("OnHide", function() PI:CloseInstall() end)
|
||||
end
|
||||
|
||||
function PI:Queue(addon)
|
||||
local addonIsQueued = false
|
||||
for _, v in pairs(self.Installs) do
|
||||
if v.Name == addon.Name then
|
||||
addonIsQueued = true
|
||||
end
|
||||
end
|
||||
|
||||
if not addonIsQueued then
|
||||
tinsert(self.Installs, #(self.Installs)+1, addon)
|
||||
self:RunInstall()
|
||||
end
|
||||
end
|
||||
|
||||
function PI:CloseInstall()
|
||||
tremove(self.Installs, 1)
|
||||
f.side:Hide()
|
||||
for i = 1, #f.side.Lines do
|
||||
f.side.Lines[i].text:SetText("")
|
||||
f.side.Lines[i]:Hide()
|
||||
end
|
||||
if #self.Installs > 0 then
|
||||
E:Delay(1, PI.RunInstall, PI)
|
||||
end
|
||||
end
|
||||
|
||||
function PI:RunInstall()
|
||||
if not E.private.install_complete then return end
|
||||
if self.Installs[1] and not PluginInstallFrame:IsShown() and not (ElvUIInstallFrame and ElvUIInstallFrame:IsShown()) then
|
||||
f.StepTitles = nil
|
||||
f.StepTitlesColor = nil
|
||||
f.StepTitlesColorSelected = nil
|
||||
local db = self.Installs[1]
|
||||
f.CurrentPage = 0
|
||||
f.MaxPage = #(db.Pages)
|
||||
|
||||
f.Title:SetText(db.Title or L["ElvUI Plugin Installation"])
|
||||
f.Status:SetMinMaxValues(0, f.MaxPage)
|
||||
f.Status.text:SetText(f.CurrentPage.." / "..f.MaxPage)
|
||||
f.tutorialImage:SetTexture(db.tutorialImage or E.Media.Textures.Logo)
|
||||
|
||||
f.Pages = db.Pages
|
||||
|
||||
PluginInstallFrame:Show()
|
||||
f:SetPoint("CENTER")
|
||||
if db.StepTitles and #db.StepTitles == f.MaxPage then
|
||||
f:SetPoint("CENTER", E.UIParent, "CENTER", -((db.StepTitleWidth or 140)/2), 0)
|
||||
f.side:SetWidth(db.StepTitleWidth or 140)
|
||||
f.side:Show()
|
||||
|
||||
for i = 1, #f.side.Lines do
|
||||
if db.StepTitles[i] then
|
||||
f.side.Lines[i]:SetWidth(db.StepTitleButtonWidth or 130)
|
||||
f.side.Lines[i].text:SetJustifyH(db.StepTitleTextJustification or "CENTER")
|
||||
f.side.Lines[i]:Show()
|
||||
end
|
||||
end
|
||||
|
||||
f.StepTitles = db.StepTitles
|
||||
f.StepTitlesColor = db.StepTitlesColor
|
||||
f.StepTitlesColorSelected = db.StepTitlesColorSelected
|
||||
end
|
||||
NextPage()
|
||||
end
|
||||
if #(self.Installs) > 1 then
|
||||
f.pending:Show()
|
||||
E:Flash(f.pending, 0.53, true)
|
||||
else
|
||||
f.pending:Hide()
|
||||
E:StopFlash(f.pending)
|
||||
end
|
||||
end
|
||||
|
||||
function PI:Initialize()
|
||||
PI.Initialized = true
|
||||
PI:CreateStepComplete()
|
||||
PI:CreateFrame()
|
||||
end
|
||||
|
||||
local function InitializeCallback()
|
||||
PI:Initialize()
|
||||
end
|
||||
|
||||
E:RegisterModule(PI:GetName(), InitializeCallback)
|
||||
@@ -0,0 +1,142 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
|
||||
-- Credit: ls- (lightspark)
|
||||
local abs, next = abs, next
|
||||
local tonumber, assert = tonumber, assert
|
||||
local activeObjects = {}
|
||||
local handledObjects = {}
|
||||
local TARGET_FPS = 60
|
||||
local AMOUNT = 0.33
|
||||
|
||||
local function lerp(startValue, endValue, amount)
|
||||
return (1 - amount) * startValue + amount * endValue
|
||||
end
|
||||
|
||||
local function clamp(v, min, max)
|
||||
min = min or 0
|
||||
max = max or 1
|
||||
|
||||
if v > max then
|
||||
return max
|
||||
elseif v < min then
|
||||
return min
|
||||
end
|
||||
|
||||
return v
|
||||
end
|
||||
|
||||
local function isCloseEnough(new, target, range)
|
||||
if range > 0 then
|
||||
return abs((new - target) / range) <= 0.001
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local frame = CreateFrame("Frame")
|
||||
local function onUpdate(_, elapsed)
|
||||
for object, target in next, activeObjects do
|
||||
local new = lerp(object._value, target, clamp(AMOUNT * elapsed * TARGET_FPS))
|
||||
if isCloseEnough(new, target, object._max - object._min) then
|
||||
new = target
|
||||
activeObjects[object] = nil
|
||||
end
|
||||
|
||||
object:SetValue_(new)
|
||||
object._value = new
|
||||
end
|
||||
end
|
||||
|
||||
local function bar_SetSmoothedValue(self, value)
|
||||
value = tonumber(value)
|
||||
|
||||
assert(value, "bar_SetSmoothedValue requires (value) to be a number.")
|
||||
|
||||
self._value = self:GetValue()
|
||||
activeObjects[self] = clamp(value, self._min, self._max)
|
||||
end
|
||||
|
||||
local function bar_SetSmoothedMinMaxValues(self, min, max)
|
||||
min, max = tonumber(min), tonumber(max)
|
||||
|
||||
assert(min and max, "bar_SetSmoothedMinMaxValues requires (min and max) to be a number.")
|
||||
|
||||
self:SetMinMaxValues_(min, max)
|
||||
|
||||
if self._max and self._max ~= max then
|
||||
local ratio = 1
|
||||
if max ~= 0 and self._max and self._max ~= 0 then
|
||||
ratio = max / (self._max or max)
|
||||
end
|
||||
|
||||
local target = activeObjects[self]
|
||||
if target then
|
||||
activeObjects[self] = target * ratio
|
||||
end
|
||||
|
||||
local cur = self._value
|
||||
if cur then
|
||||
self:SetValue_(cur * ratio)
|
||||
self._value = cur * ratio
|
||||
end
|
||||
end
|
||||
|
||||
self._min = min
|
||||
self._max = max
|
||||
end
|
||||
|
||||
local function SmoothBar(bar)
|
||||
bar._min, bar._max = bar:GetMinMaxValues()
|
||||
bar._value = bar:GetValue()
|
||||
|
||||
if not bar.SetValue_ then
|
||||
bar.SetValue_ = bar.SetValue
|
||||
bar.SetValue = bar_SetSmoothedValue
|
||||
end
|
||||
if not bar.SetMinMaxValues_ then
|
||||
bar.SetMinMaxValues_ = bar.SetMinMaxValues
|
||||
bar.SetMinMaxValues = bar_SetSmoothedMinMaxValues
|
||||
end
|
||||
|
||||
if not frame:GetScript("OnUpdate") then
|
||||
frame:SetScript("OnUpdate", onUpdate)
|
||||
end
|
||||
|
||||
handledObjects[bar] = true
|
||||
end
|
||||
|
||||
local function DesmoothBar(bar)
|
||||
if activeObjects[bar] then
|
||||
bar:SetValue_(activeObjects[bar])
|
||||
activeObjects[bar] = nil
|
||||
end
|
||||
|
||||
if handledObjects[bar] then
|
||||
handledObjects[bar] = nil
|
||||
end
|
||||
|
||||
if bar.SetValue_ then
|
||||
bar.SetValue = bar.SetValue_
|
||||
bar.SetValue_ = nil
|
||||
end
|
||||
if bar.SetMinMaxValues_ then
|
||||
bar.SetMinMaxValues = bar.SetMinMaxValues_
|
||||
bar.SetMinMaxValues_ = nil
|
||||
end
|
||||
|
||||
if not next(handledObjects) then
|
||||
frame:SetScript("OnUpdate", nil)
|
||||
end
|
||||
end
|
||||
|
||||
function E:SetSmoothingAmount(amount)
|
||||
AMOUNT = clamp(amount, 0.2, 0.8)
|
||||
end
|
||||
|
||||
function E:SetSmoothing(bar, enable)
|
||||
if enable then
|
||||
SmoothBar(bar)
|
||||
else
|
||||
DesmoothBar(bar)
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,208 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local Skins = E:GetModule("Skins")
|
||||
|
||||
--Lua functions
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local GetAddOnInfo = GetAddOnInfo
|
||||
local GetCurrentResolution = GetCurrentResolution
|
||||
local GetCVar = GetCVar
|
||||
local GetLocale = GetLocale
|
||||
local GetNumAddOns = GetNumAddOns
|
||||
local GetRealZoneText = GetRealZoneText
|
||||
local GetScreenResolutions = GetScreenResolutions
|
||||
|
||||
local function AreOtherAddOnsEnabled()
|
||||
local name, loadable, reason, _
|
||||
for i = 1, GetNumAddOns() do
|
||||
name, _, _, loadable, reason = GetAddOnInfo(i)
|
||||
if (name ~= "ElvUI" and name ~= "ElvUI_OptionsUI") and (loadable or (not loadable and reason == "DEMAND_LOADED")) then --Loaded or load on demand
|
||||
return "Yes"
|
||||
end
|
||||
end
|
||||
|
||||
return "No"
|
||||
end
|
||||
|
||||
local function GetDisplayMode()
|
||||
local window, maximize = GetCVar("gxWindow"), GetCVar("gxMaximize")
|
||||
local displayMode
|
||||
|
||||
if window == "1" then
|
||||
if maximize == "1" then
|
||||
displayMode = "Windowed (Fullscreen)"
|
||||
else
|
||||
displayMode = "Windowed"
|
||||
end
|
||||
else
|
||||
displayMode = "Fullscreen"
|
||||
end
|
||||
|
||||
return displayMode
|
||||
end
|
||||
|
||||
local function GetResolution()
|
||||
return (({GetScreenResolutions()})[GetCurrentResolution()] or GetCVar("gxWindowedResolution"))
|
||||
end
|
||||
|
||||
function E:CreateStatusFrame()
|
||||
local function CreateSection(width, height, parent, anchor1, anchorTo, anchor2, yOffset)
|
||||
local section = CreateFrame("Frame", nil, parent)
|
||||
section:Size(width, height)
|
||||
section:Point(anchor1, anchorTo, anchor2, 0, yOffset)
|
||||
|
||||
section.Header = CreateFrame("Frame", nil, section)
|
||||
section.Header:Size(300, 30)
|
||||
section.Header:Point("TOP", section)
|
||||
|
||||
section.Header.Text = section.Header:CreateFontString(nil, "ARTWORK", "NumberFont_Outline_Large")
|
||||
section.Header.Text:Point("TOP")
|
||||
section.Header.Text:Point("BOTTOM")
|
||||
section.Header.Text:SetJustifyH("CENTER")
|
||||
section.Header.Text:SetJustifyV("MIDDLE")
|
||||
local font, fontHeight, flags = section.Header.Text:GetFont()
|
||||
section.Header.Text:SetFont(font, fontHeight*1.3, flags)
|
||||
|
||||
section.Header.LeftDivider = section.Header:CreateTexture(nil, "ARTWORK")
|
||||
section.Header.LeftDivider:Height(8)
|
||||
section.Header.LeftDivider:Point("LEFT", section.Header, "LEFT", 5, 0)
|
||||
section.Header.LeftDivider:Point("RIGHT", section.Header.Text, "LEFT", -5, 0)
|
||||
section.Header.LeftDivider:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
|
||||
section.Header.LeftDivider:SetTexCoord(0.81, 0.94, 0.5, 1)
|
||||
|
||||
section.Header.RightDivider = section.Header:CreateTexture(nil, "ARTWORK")
|
||||
section.Header.RightDivider:Height(8)
|
||||
section.Header.RightDivider:Point("RIGHT", section.Header, "RIGHT", -5, 0)
|
||||
section.Header.RightDivider:Point("LEFT", section.Header.Text, "RIGHT", 5, 0)
|
||||
section.Header.RightDivider:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
|
||||
section.Header.RightDivider:SetTexCoord(0.81, 0.94, 0.5, 1)
|
||||
|
||||
return section
|
||||
end
|
||||
|
||||
local function CreateContentLines(num, parent, anchorTo)
|
||||
local content = CreateFrame("Frame", nil, parent)
|
||||
content:Size(240, (num * 20) + ((num - 1) * 5)) --20 height and 5 spacing
|
||||
content:Point("TOP", anchorTo, "BOTTOM", 0, -5)
|
||||
for i = 1, num do
|
||||
local line = CreateFrame("Frame", nil, content)
|
||||
line:Size(240, 20)
|
||||
line.Text = line:CreateFontString(nil, "ARTWORK", "NumberFont_Outline_Large")
|
||||
line.Text:SetAllPoints()
|
||||
line.Text:SetJustifyH("LEFT")
|
||||
line.Text:SetJustifyV("MIDDLE")
|
||||
content["Line"..i] = line
|
||||
|
||||
if i == 1 then
|
||||
content["Line"..i]:Point("TOP", content, "TOP")
|
||||
else
|
||||
content["Line"..i]:Point("TOP", content["Line"..(i - 1)], "BOTTOM", 0, -5)
|
||||
end
|
||||
end
|
||||
|
||||
return content
|
||||
end
|
||||
|
||||
--Main frame
|
||||
local StatusFrame = CreateFrame("Frame", "ElvUIStatusReport", E.UIParent)
|
||||
StatusFrame:Size(300, 640)
|
||||
StatusFrame:Point("CENTER", E.UIParent, "CENTER")
|
||||
StatusFrame:SetFrameStrata("HIGH")
|
||||
StatusFrame:CreateBackdrop("Transparent", nil, true)
|
||||
StatusFrame:Hide()
|
||||
StatusFrame:CreateCloseButton()
|
||||
StatusFrame:SetClampedToScreen(true)
|
||||
StatusFrame:SetMovable(true)
|
||||
StatusFrame:EnableMouse(true)
|
||||
StatusFrame:RegisterForDrag("LeftButton", "RightButton")
|
||||
StatusFrame:SetScript("OnDragStart", function(self)
|
||||
self:StartMoving()
|
||||
end)
|
||||
StatusFrame:SetScript("OnDragStop", function(self)
|
||||
self:StopMovingOrSizing()
|
||||
end)
|
||||
|
||||
--Title logo
|
||||
StatusFrame.TitleLogoFrame = CreateFrame("Frame", nil, StatusFrame)
|
||||
StatusFrame.TitleLogoFrame:Size(128, 64)
|
||||
StatusFrame.TitleLogoFrame:Point("CENTER", StatusFrame, "TOP", 0, 0)
|
||||
StatusFrame.TitleLogoFrame.Texture = StatusFrame.TitleLogoFrame:CreateTexture(nil, "ARTWORK")
|
||||
StatusFrame.TitleLogoFrame.Texture:SetTexture(E.Media.Textures.Logo)
|
||||
StatusFrame.TitleLogoFrame.Texture:SetAllPoints()
|
||||
|
||||
--Sections
|
||||
StatusFrame.Section1 = CreateSection(300, 150, StatusFrame, "TOP", StatusFrame, "TOP", -30)
|
||||
StatusFrame.Section2 = CreateSection(300, 175, StatusFrame, "TOP", StatusFrame.Section1, "BOTTOM", 0)
|
||||
StatusFrame.Section3 = CreateSection(300, 220, StatusFrame, "TOP", StatusFrame.Section2, "BOTTOM", 0)
|
||||
StatusFrame.Section4 = CreateSection(300, 60, StatusFrame, "TOP", StatusFrame.Section3, "BOTTOM", 0)
|
||||
|
||||
--Section headers
|
||||
StatusFrame.Section1.Header.Text:SetText("|cfffe7b2cAddOn Info|r")
|
||||
StatusFrame.Section2.Header.Text:SetText("|cfffe7b2cWoW Info|r")
|
||||
StatusFrame.Section3.Header.Text:SetText("|cfffe7b2cCharacter Info|r")
|
||||
StatusFrame.Section4.Header.Text:SetText("|cfffe7b2cExport To|r")
|
||||
|
||||
--Section content
|
||||
StatusFrame.Section1.Content = CreateContentLines(4, StatusFrame.Section1, StatusFrame.Section1.Header)
|
||||
StatusFrame.Section2.Content = CreateContentLines(5, StatusFrame.Section2, StatusFrame.Section2.Header)
|
||||
StatusFrame.Section3.Content = CreateContentLines(5, StatusFrame.Section3, StatusFrame.Section3.Header)
|
||||
StatusFrame.Section4.Content = CreateFrame("Frame", nil, StatusFrame.Section4)
|
||||
StatusFrame.Section4.Content:Size(240, 25)
|
||||
StatusFrame.Section4.Content:Point("TOP", StatusFrame.Section4.Header, "BOTTOM", 0, 0)
|
||||
|
||||
--Content lines
|
||||
StatusFrame.Section1.Content.Line1.Text:SetFormattedText("Version of ElvUI: |cff4beb2c%s|r", E.version)
|
||||
StatusFrame.Section1.Content.Line2.Text:SetFormattedText("Other AddOns Enabled: |cff4beb2c%s|r", AreOtherAddOnsEnabled())
|
||||
StatusFrame.Section1.Content.Line3.Text:SetFormattedText("Recommended Scale: |cff4beb2c%s|r", E:PixelBestSize())
|
||||
StatusFrame.Section1.Content.Line4.Text:SetFormattedText("UI Scale Is: |cff4beb2c%s|r", E.global.general.UIScale)
|
||||
|
||||
StatusFrame.Section2.Content.Line1.Text:SetFormattedText("Version of WoW: |cff4beb2c%s (build %s)|r", E.wowpatch, E.wowbuild)
|
||||
StatusFrame.Section2.Content.Line2.Text:SetFormattedText("Client Language: |cff4beb2c%s|r", GetLocale())
|
||||
StatusFrame.Section2.Content.Line3.Text:SetFormattedText("Display Mode: |cff4beb2c%s|r", GetDisplayMode())
|
||||
StatusFrame.Section2.Content.Line4.Text:SetFormattedText("Resolution: |cff4beb2c%s|r", GetResolution())
|
||||
StatusFrame.Section2.Content.Line5.Text:SetFormattedText("Using Mac Client: |cff4beb2c%s|r", (E.isMacClient == true and "Yes" or "No"))
|
||||
|
||||
StatusFrame.Section3.Content.Line1.Text:SetFormattedText("Faction: |cff4beb2c%s|r", E.myfaction)
|
||||
StatusFrame.Section3.Content.Line2.Text:SetFormattedText("Race: |cff4beb2c%s|r", E.myrace)
|
||||
StatusFrame.Section3.Content.Line3.Text:SetFormattedText("Level: |cff4beb2c%s|r", E.mylevel)
|
||||
StatusFrame.Section3.Content.Line4.Text:SetFormattedText("Zone: |cff4beb2c%s|r", GetRealZoneText())
|
||||
StatusFrame.Section3.Content.Line5.Text:SetFormattedText("Realm: |cff4beb2c%s|r", E.myrealm)
|
||||
|
||||
--Export buttons
|
||||
StatusFrame.Section4.Content.Button1 = CreateFrame("Button", nil, StatusFrame.Section4.Content, "UIPanelButtonTemplate")
|
||||
StatusFrame.Section4.Content.Button1:Size(100, 25)
|
||||
StatusFrame.Section4.Content.Button1:Point("LEFT", StatusFrame.Section4.Content, "LEFT")
|
||||
StatusFrame.Section4.Content.Button1:SetText("Forum")
|
||||
StatusFrame.Section4.Content.Button1:SetButtonState("DISABLED")
|
||||
Skins:HandleButton(StatusFrame.Section4.Content.Button1, true)
|
||||
|
||||
StatusFrame.Section4.Content.Button2 = CreateFrame("Button", nil, StatusFrame.Section4.Content, "UIPanelButtonTemplate")
|
||||
StatusFrame.Section4.Content.Button2:Size(100, 25)
|
||||
StatusFrame.Section4.Content.Button2:Point("RIGHT", StatusFrame.Section4.Content, "RIGHT")
|
||||
StatusFrame.Section4.Content.Button2:SetText("Ticket")
|
||||
StatusFrame.Section4.Content.Button2:SetButtonState("DISABLED")
|
||||
Skins:HandleButton(StatusFrame.Section4.Content.Button2, true)
|
||||
|
||||
E.StatusFrame = StatusFrame
|
||||
end
|
||||
|
||||
local function UpdateDynamicValues()
|
||||
E.StatusFrame.Section2.Content.Line3.Text:SetFormattedText("Display Mode: |cff4beb2c%s|r", GetDisplayMode())
|
||||
E.StatusFrame.Section2.Content.Line4.Text:SetFormattedText("Resolution: |cff4beb2c%s|r", GetResolution())
|
||||
E.StatusFrame.Section3.Content.Line3.Text:SetFormattedText("Level: |cff4beb2c%s|r", E.mylevel)
|
||||
E.StatusFrame.Section3.Content.Line4.Text:SetFormattedText("Zone: |cff4beb2c%s|r", GetRealZoneText())
|
||||
end
|
||||
|
||||
function E:ShowStatusReport()
|
||||
if not self.StatusFrame then
|
||||
self:CreateStatusFrame()
|
||||
end
|
||||
|
||||
if not self.StatusFrame:IsShown() then
|
||||
UpdateDynamicValues()
|
||||
self.StatusFrame:Raise() --Set framelevel above everything else
|
||||
self.StatusFrame:Show()
|
||||
else
|
||||
self.StatusFrame:Hide()
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,756 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local ElvUF = E.oUF
|
||||
|
||||
local Translit = E.Libs.Translit
|
||||
local translitMark = "!"
|
||||
|
||||
--Lua functions
|
||||
local select = select
|
||||
local tonumber = tonumber
|
||||
local find = string.find
|
||||
local floor = math.floor
|
||||
local format = string.format
|
||||
local gmatch = gmatch
|
||||
local gsub = gsub
|
||||
local match = string.match
|
||||
local utf8lower = string.utf8lower
|
||||
local utf8sub = string.utf8sub
|
||||
--WoW API / Variables
|
||||
local GetGuildInfo = GetGuildInfo
|
||||
local GetInstanceInfo = GetInstanceInfo
|
||||
local GetNumPartyMembers = GetNumPartyMembers
|
||||
local GetPVPTimer = GetPVPTimer
|
||||
local GetQuestGreenRange = GetQuestGreenRange
|
||||
local GetThreatStatusColor = GetThreatStatusColor
|
||||
local GetTime = GetTime
|
||||
local GetUnitSpeed = GetUnitSpeed
|
||||
local UnitClass = UnitClass
|
||||
local UnitClassification = UnitClassification
|
||||
local UnitDetailedThreatSituation = UnitDetailedThreatSituation
|
||||
local UnitExists = UnitExists
|
||||
local UnitGUID = UnitGUID
|
||||
local UnitHealth = UnitHealth
|
||||
local UnitHealthMax = UnitHealthMax
|
||||
local UnitIsAFK = UnitIsAFK
|
||||
local UnitIsConnected = UnitIsConnected
|
||||
local UnitIsDND = UnitIsDND
|
||||
local UnitIsDead = UnitIsDead
|
||||
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
|
||||
local UnitIsGhost = UnitIsGhost
|
||||
local UnitIsPVP = UnitIsPVP
|
||||
local UnitIsPVPFreeForAll = UnitIsPVPFreeForAll
|
||||
local UnitIsPlayer = UnitIsPlayer
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local UnitLevel = UnitLevel
|
||||
local UnitName = UnitName
|
||||
local UnitPVPName = UnitPVPName
|
||||
local UnitPower = UnitPower
|
||||
local UnitPowerMax = UnitPowerMax
|
||||
local UnitPowerType = UnitPowerType
|
||||
local UnitReaction = UnitReaction
|
||||
local DEFAULT_AFK_MESSAGE = DEFAULT_AFK_MESSAGE
|
||||
local SPELL_POWER_MANA = SPELL_POWER_MANA
|
||||
local PVP = PVP
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- Tags
|
||||
------------------------------------------------------------------------
|
||||
|
||||
local function abbrev(name)
|
||||
local letters, lastWord = "", match(name, ".+%s(.+)$")
|
||||
if lastWord then
|
||||
for word in gmatch(name, ".-%s") do
|
||||
local firstLetter = utf8sub(gsub(word, "^[%s%p]*", ""), 1, 1)
|
||||
if firstLetter ~= utf8lower(firstLetter) then
|
||||
letters = format("%s%s. ", letters, firstLetter)
|
||||
end
|
||||
end
|
||||
name = format("%s%s", letters, lastWord)
|
||||
end
|
||||
return name
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["afk"] = "PLAYER_FLAGS_CHANGED"
|
||||
ElvUF.Tags.Methods["afk"] = function(unit)
|
||||
local isAFK = UnitIsAFK(unit)
|
||||
if isAFK then
|
||||
return format("|cffFFFFFF[|r|cffFF0000%s|r|cFFFFFFFF]|r", DEFAULT_AFK_MESSAGE)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["healthcolor"] = "UNIT_HEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED"
|
||||
ElvUF.Tags.Methods["healthcolor"] = function(unit)
|
||||
if UnitIsDeadOrGhost(unit) or not UnitIsConnected(unit) then
|
||||
return Hex(0.84, 0.75, 0.65)
|
||||
else
|
||||
local r, g, b = ElvUF:ColorGradient(UnitHealth(unit), UnitHealthMax(unit), 0.69, 0.31, 0.31, 0.65, 0.63, 0.35, 0.33, 0.59, 0.33)
|
||||
return Hex(r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["name:abbrev"] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods["name:abbrev"] = function(unit)
|
||||
local name = UnitName(unit)
|
||||
|
||||
if name and find(name, "%s") then
|
||||
name = abbrev(name)
|
||||
end
|
||||
|
||||
return name ~= nil and name or ""
|
||||
end
|
||||
|
||||
for textFormat in pairs(E.GetFormattedTextStyles) do
|
||||
local tagTextFormat = strlower(gsub(textFormat, "_", "-"))
|
||||
ElvUF.Tags.Events[format("health:%s", tagTextFormat)] = "UNIT_HEALTH UNIT_MAXHEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED"
|
||||
ElvUF.Tags.Methods[format("health:%s", tagTextFormat)] = function(unit)
|
||||
local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
|
||||
if status then
|
||||
return status
|
||||
else
|
||||
return E:GetFormattedText(textFormat, UnitHealth(unit), UnitHealthMax(unit))
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("health:%s-nostatus", tagTextFormat)] = "UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH"
|
||||
ElvUF.Tags.Methods[format("health:%s-nostatus", tagTextFormat)] = function(unit)
|
||||
return E:GetFormattedText(textFormat, UnitHealth(unit), UnitHealthMax(unit))
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("power:%s", tagTextFormat)] = "UNIT_MAXENERGY UNIT_MAXFOCUS UNIT_MAXMANA UNIT_MAXRAGE UNIT_ENERGY UNIT_FOCUS UNIT_MANA UNIT_RAGE UNIT_MAXRUNIC_POWER UNIT_RUNIC_POWER"
|
||||
ElvUF.Tags.Methods[format("power:%s", tagTextFormat)] = function(unit)
|
||||
local pType = UnitPowerType(unit)
|
||||
local min = UnitPower(unit, pType)
|
||||
|
||||
if min == 0 and tagTextFormat ~= "deficit" then
|
||||
return ""
|
||||
else
|
||||
return E:GetFormattedText(textFormat, UnitPower(unit, pType), UnitPowerMax(unit, pType))
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("mana:%s", tagTextFormat)] = "UNIT_MANA UNIT_MAXMANA"
|
||||
ElvUF.Tags.Methods[format("mana:%s", tagTextFormat)] = function(unit)
|
||||
local min = UnitPower(unit, SPELL_POWER_MANA)
|
||||
|
||||
if min == 0 and tagTextFormat ~= "deficit" then
|
||||
return ""
|
||||
else
|
||||
return E:GetFormattedText(textFormat, UnitPower(unit, SPELL_POWER_MANA), UnitPowerMax(unit, SPELL_POWER_MANA))
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("energy:%s", tagTextFormat)] = "UNIT_MAXENERGY UNIT_ENERGY_FREQUENT"
|
||||
ElvUF.Tags.Methods[format("energy:%s", tagTextFormat)] = function(unit)
|
||||
local min = UnitPower(unit, 3)
|
||||
|
||||
if min == 0 and tagTextFormat ~= "deficit" then
|
||||
return ""
|
||||
else
|
||||
return E:GetFormattedText(textFormat, UnitPower(unit, 3), UnitPowerMax(unit, 3))
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("rage:%s", tagTextFormat)] = "UNIT_MAXRAGE UNIT_RAGE_FREQUENT"
|
||||
ElvUF.Tags.Methods[format("rage:%s", tagTextFormat)] = function(unit)
|
||||
local min = UnitPower(unit, 1)
|
||||
|
||||
if min == 0 and tagTextFormat ~= "deficit" then
|
||||
return ""
|
||||
else
|
||||
return E:GetFormattedText(textFormat, UnitPower(unit, 1), UnitPowerMax(unit, 1))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for textFormat, length in pairs({veryshort = 5, short = 10, medium = 15, long = 20}) do
|
||||
ElvUF.Tags.Events[format("health:deficit-percent:name-%s", textFormat)] = "UNIT_HEALTH UNIT_MAXHEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED"
|
||||
ElvUF.Tags.Methods[format("health:deficit-percent:name-%s", textFormat)] = function(unit)
|
||||
local cur, max = UnitHealth(unit), UnitHealthMax(unit)
|
||||
local deficit = max - cur
|
||||
|
||||
if deficit > 0 and cur > 0 then
|
||||
return _TAGS["health:percent-nostatus"](unit)
|
||||
else
|
||||
return _TAGS[format("name:%s", textFormat)](unit)
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("name:abbrev:%s", textFormat)] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods[format("name:abbrev:%s", textFormat)] = function(unit)
|
||||
local name = UnitName(unit)
|
||||
|
||||
if name and find(name, "%s") then
|
||||
name = abbrev(name)
|
||||
end
|
||||
|
||||
return name ~= nil and E:ShortenString(name, length) or ""
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("name:%s", textFormat)] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods[format("name:%s", textFormat)] = function(unit)
|
||||
local name = UnitName(unit)
|
||||
return name ~= nil and E:ShortenString(name, length) or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("name:%s:status", textFormat)] = "UNIT_NAME_UPDATE UNIT_CONNECTION PLAYER_FLAGS_CHANGED UNIT_HEALTH_FREQUENT"
|
||||
ElvUF.Tags.Methods[format("name:%s:status", textFormat)] = function(unit)
|
||||
local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
|
||||
local name = UnitName(unit)
|
||||
if (status) then
|
||||
return status
|
||||
else
|
||||
return name ~= nil and E:ShortenString(name, length) or nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("name:%s:translit", textFormat)] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods[format("name:%s:translit", textFormat)] = function(unit)
|
||||
local name = Translit:Transliterate(UnitName(unit), translitMark)
|
||||
return name ~= nil and E:ShortenString(name, length) or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("target:%s", textFormat)] = "UNIT_TARGET"
|
||||
ElvUF.Tags.Methods[format("target:%s", textFormat)] = function(unit)
|
||||
local targetName = UnitName(unit.."target")
|
||||
return targetName ~= nil and E:ShortenString(targetName, length) or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events[format("target:%s:translit", textFormat)] = "UNIT_TARGET"
|
||||
ElvUF.Tags.Methods[format("target:%s:translit", textFormat)] = function(unit)
|
||||
local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
|
||||
return targetName ~= nil and E:ShortenString(targetName, length) or nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["health:max"] = "UNIT_MAXHEALTH"
|
||||
ElvUF.Tags.Methods["health:max"] = function(unit)
|
||||
local max = UnitHealthMax(unit)
|
||||
|
||||
return E:GetFormattedText("CURRENT", max, max)
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["health:deficit-percent:name"] = "UNIT_HEALTH UNIT_MAXHEALTH"
|
||||
ElvUF.Tags.Methods["health:deficit-percent:name"] = function(unit)
|
||||
local currentHealth = UnitHealth(unit)
|
||||
local deficit = UnitHealthMax(unit) - currentHealth
|
||||
|
||||
if deficit > 0 and currentHealth > 0 then
|
||||
return _TAGS["health:percent-nostatus"](unit)
|
||||
else
|
||||
return _TAGS.name(unit)
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["power:max"] = "UNIT_MAXENERGY UNIT_MAXFOCUS UNIT_MAXMANA UNIT_MAXRAGE UNIT_MAXRUNIC_POWER"
|
||||
ElvUF.Tags.Methods["power:max"] = function(unit)
|
||||
local pType = UnitPowerType(unit)
|
||||
local max = UnitPowerMax(unit, pType)
|
||||
|
||||
return E:GetFormattedText("CURRENT", max, max)
|
||||
end
|
||||
|
||||
ElvUF.Tags.Methods["manacolor"] = function()
|
||||
local mana = PowerBarColor.MANA
|
||||
local altR, altG, altB = mana.r, mana.g, mana.b
|
||||
local color = ElvUF.colors.power.MANA
|
||||
if color then
|
||||
return Hex(color[1], color[2], color[3])
|
||||
else
|
||||
return Hex(altR, altG, altB)
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["mana:max"] = "UNIT_MAXMANA"
|
||||
ElvUF.Tags.Methods["mana:max"] = function(unit)
|
||||
local max = UnitPowerMax(unit, SPELL_POWER_MANA)
|
||||
|
||||
return E:GetFormattedText("CURRENT", max, max)
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["difficultycolor"] = "UNIT_LEVEL PLAYER_LEVEL_UP"
|
||||
ElvUF.Tags.Methods["difficultycolor"] = function(unit)
|
||||
local r, g, b
|
||||
local level = UnitLevel(unit)
|
||||
if level > 1 then
|
||||
local DiffColor = UnitLevel(unit) - UnitLevel("player")
|
||||
if DiffColor >= 5 then
|
||||
r, g, b = 0.69, 0.31, 0.31
|
||||
elseif DiffColor >= 3 then
|
||||
r, g, b = 0.71, 0.43, 0.27
|
||||
elseif DiffColor >= -2 then
|
||||
r, g, b = 0.84, 0.75, 0.65
|
||||
elseif -DiffColor <= GetQuestGreenRange() then
|
||||
r, g, b = 0.33, 0.59, 0.33
|
||||
else
|
||||
r, g, b = 0.55, 0.57, 0.61
|
||||
end
|
||||
end
|
||||
|
||||
return Hex(r, g, b)
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["namecolor"] = "UNIT_NAME_UPDATE UNIT_FACTION"
|
||||
ElvUF.Tags.Methods["namecolor"] = function(unit)
|
||||
local unitReaction = UnitReaction(unit, "player")
|
||||
local unitPlayer = UnitIsPlayer(unit)
|
||||
if unitPlayer then
|
||||
return Hex(E.media.herocolor.r, E.media.herocolor.g, E.media.herocolor.b)
|
||||
elseif unitReaction then
|
||||
local reaction = ElvUF.colors.reaction[unitReaction]
|
||||
return Hex(reaction[1], reaction[2], reaction[3])
|
||||
else
|
||||
return "|cFFC2C2C2"
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["smartlevel"] = "UNIT_LEVEL PLAYER_LEVEL_UP"
|
||||
ElvUF.Tags.Methods["smartlevel"] = function(unit)
|
||||
local level = UnitLevel(unit)
|
||||
if level == UnitLevel("player") then
|
||||
return ""
|
||||
elseif level > 0 then
|
||||
return level
|
||||
else
|
||||
return "??"
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["realm"] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods["realm"] = function(unit)
|
||||
local _, realm = UnitName(unit)
|
||||
|
||||
if realm and realm ~= "" then
|
||||
return realm
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["realm:dash"] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods["realm:dash"] = function(unit)
|
||||
local _, realm = UnitName(unit)
|
||||
|
||||
if realm and (realm ~= "" and realm ~= E.myrealm) then
|
||||
realm = format("-%s", realm)
|
||||
elseif realm == "" then
|
||||
realm = nil
|
||||
end
|
||||
|
||||
return realm
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["realm:translit"] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods["realm:translit"] = function(unit)
|
||||
local _, realm = Translit:Transliterate(UnitName(unit), translitMark)
|
||||
|
||||
if realm and realm ~= "" then
|
||||
return realm
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["realm:dash:translit"] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods["realm:dash:translit"] = function(unit)
|
||||
local _, realm = Translit:Transliterate(UnitName(unit), translitMark)
|
||||
|
||||
if realm and (realm ~= "" and realm ~= E.myrealm) then
|
||||
realm = format("-%s", realm)
|
||||
elseif realm == "" then
|
||||
realm = nil
|
||||
end
|
||||
|
||||
return realm
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["threat:percent"] = "UNIT_THREAT_SITUATION_UPDATE UNIT_THREAT_LIST_UPDATE"
|
||||
ElvUF.Tags.Methods["threat:percent"] = function(unit)
|
||||
local _, _, percent = UnitDetailedThreatSituation("player", unit)
|
||||
if percent and percent > 0 and (GetNumPartyMembers() or UnitExists("pet")) then
|
||||
return format("%.0f%%", percent)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["threat:current"] = "UNIT_THREAT_SITUATION_UPDATE UNIT_THREAT_LIST_UPDATE"
|
||||
ElvUF.Tags.Methods["threat:current"] = function(unit)
|
||||
local _, _, percent, _, threatvalue = UnitDetailedThreatSituation("player", unit)
|
||||
if percent and percent > 0 and (GetNumPartyMembers() or UnitExists("pet")) then
|
||||
return E:ShortValue(threatvalue)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["threatcolor"] = "UNIT_THREAT_SITUATION_UPDATE UNIT_THREAT_LIST_UPDATE"
|
||||
ElvUF.Tags.Methods["threatcolor"] = function(unit)
|
||||
local _, status = UnitDetailedThreatSituation("player", unit)
|
||||
if status and (GetNumPartyMembers() > 0 or UnitExists("pet")) then
|
||||
return Hex(GetThreatStatusColor(status))
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local unitStatus = {}
|
||||
ElvUF.Tags.OnUpdateThrottle["statustimer"] = 1
|
||||
ElvUF.Tags.Methods["statustimer"] = function(unit)
|
||||
if not UnitIsPlayer(unit) then return end
|
||||
local guid = UnitGUID(unit)
|
||||
if UnitIsAFK(unit) then
|
||||
if not unitStatus[guid] or unitStatus[guid] and unitStatus[guid][1] ~= "AFK" then
|
||||
unitStatus[guid] = {"AFK", GetTime()}
|
||||
end
|
||||
elseif UnitIsDND(unit) then
|
||||
if not unitStatus[guid] or unitStatus[guid] and unitStatus[guid][1] ~= "DND" then
|
||||
unitStatus[guid] = {"DND", GetTime()}
|
||||
end
|
||||
elseif UnitIsDead(unit) or UnitIsGhost(unit) then
|
||||
if not unitStatus[guid] or unitStatus[guid] and unitStatus[guid][1] ~= "Dead" then
|
||||
unitStatus[guid] = {"Dead", GetTime()}
|
||||
end
|
||||
elseif not UnitIsConnected(unit) then
|
||||
if not unitStatus[guid] or unitStatus[guid] and unitStatus[guid][1] ~= "Offline" then
|
||||
unitStatus[guid] = {"Offline", GetTime()}
|
||||
end
|
||||
else
|
||||
unitStatus[guid] = nil
|
||||
end
|
||||
|
||||
if unitStatus[guid] ~= nil then
|
||||
local status = unitStatus[guid][1]
|
||||
local timer = GetTime() - unitStatus[guid][2]
|
||||
local mins = floor(timer / 60)
|
||||
local secs = floor(timer - (mins * 60))
|
||||
return format("%s (%01.f:%02.f)", status, mins, secs)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.OnUpdateThrottle["pvptimer"] = 1
|
||||
ElvUF.Tags.Methods["pvptimer"] = function(unit)
|
||||
if UnitIsPVPFreeForAll(unit) or UnitIsPVP(unit) then
|
||||
local timer = GetPVPTimer()
|
||||
|
||||
if timer ~= 301000 and timer ~= -1 then
|
||||
local mins = floor((timer / 1000) / 60)
|
||||
local secs = floor((timer / 1000) - (mins * 60))
|
||||
return format("%s (%01.f:%02.f)", PVP, mins, secs)
|
||||
else
|
||||
return PVP
|
||||
end
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local baseSpeed = 7
|
||||
local speedText = SPEED
|
||||
|
||||
ElvUF.Tags.OnUpdateThrottle["speed:percent"] = 0.1
|
||||
ElvUF.Tags.Methods["speed:percent"] = function(unit)
|
||||
local currentSpeedInYards = GetUnitSpeed(unit)
|
||||
local currentSpeedInPercent = (currentSpeedInYards / baseSpeed) * 100
|
||||
|
||||
return format("%s: %d%%", speedText, currentSpeedInPercent)
|
||||
end
|
||||
|
||||
ElvUF.Tags.OnUpdateThrottle["speed:percent-moving"] = 0.1
|
||||
ElvUF.Tags.Methods["speed:percent-moving"] = function(unit)
|
||||
local currentSpeedInYards = GetUnitSpeed(unit)
|
||||
local currentSpeedInPercent = currentSpeedInYards > 0 and ((currentSpeedInYards / baseSpeed) * 100)
|
||||
|
||||
if currentSpeedInPercent then
|
||||
currentSpeedInPercent = format("%s: %d%%", speedText, currentSpeedInPercent)
|
||||
end
|
||||
|
||||
return currentSpeedInPercent or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.OnUpdateThrottle["speed:percent-raw"] = 0.1
|
||||
ElvUF.Tags.Methods["speed:percent-raw"] = function(unit)
|
||||
local currentSpeedInYards = GetUnitSpeed(unit)
|
||||
local currentSpeedInPercent = (currentSpeedInYards / baseSpeed) * 100
|
||||
|
||||
return format("%d%%", currentSpeedInPercent)
|
||||
end
|
||||
|
||||
ElvUF.Tags.OnUpdateThrottle["speed:percent-moving-raw"] = 0.1
|
||||
ElvUF.Tags.Methods["speed:percent-moving-raw"] = function(unit)
|
||||
local currentSpeedInYards = GetUnitSpeed(unit)
|
||||
local currentSpeedInPercent = currentSpeedInYards > 0 and ((currentSpeedInYards / baseSpeed) * 100)
|
||||
|
||||
if currentSpeedInPercent then
|
||||
currentSpeedInPercent = format("%d%%", currentSpeedInPercent)
|
||||
end
|
||||
|
||||
return currentSpeedInPercent or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.OnUpdateThrottle["speed:yardspersec"] = 0.1
|
||||
ElvUF.Tags.Methods["speed:yardspersec"] = function(unit)
|
||||
local currentSpeedInYards = GetUnitSpeed(unit)
|
||||
|
||||
return format("%s: %.1f", speedText, currentSpeedInYards)
|
||||
end
|
||||
|
||||
ElvUF.Tags.OnUpdateThrottle["speed:yardspersec-moving"] = 0.1
|
||||
ElvUF.Tags.Methods["speed:yardspersec-moving"] = function(unit)
|
||||
local currentSpeedInYards = GetUnitSpeed(unit)
|
||||
|
||||
return currentSpeedInYards > 0 and format("%s: %.1f", speedText, currentSpeedInYards) or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.OnUpdateThrottle["speed:yardspersec-raw"] = 0.1
|
||||
ElvUF.Tags.Methods["speed:yardspersec-raw"] = function(unit)
|
||||
local currentSpeedInYards = GetUnitSpeed(unit)
|
||||
return format("%.1f", currentSpeedInYards)
|
||||
end
|
||||
|
||||
ElvUF.Tags.OnUpdateThrottle["speed:yardspersec-moving-raw"] = 0.1
|
||||
ElvUF.Tags.Methods["speed:yardspersec-moving-raw"] = function(unit)
|
||||
local currentSpeedInYards = GetUnitSpeed(unit)
|
||||
|
||||
return currentSpeedInYards > 0 and format("%.1f", currentSpeedInYards) or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["classificationcolor"] = "UNIT_CLASSIFICATION_CHANGED"
|
||||
ElvUF.Tags.Methods["classificationcolor"] = function(unit)
|
||||
local c = UnitClassification(unit)
|
||||
if c == "rare" or c == "elite" then
|
||||
return Hex(1, 0.5, 0.25) -- Orange
|
||||
elseif c == "rareelite" or c == "worldboss" then
|
||||
return Hex(1, 0, 0) -- Red
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.SharedEvents.PLAYER_GUILD_UPDATE = true
|
||||
|
||||
ElvUF.Tags.Events["guild"] = "UNIT_NAME_UPDATE PLAYER_GUILD_UPDATE"
|
||||
ElvUF.Tags.Methods["guild"] = function(unit)
|
||||
if (UnitIsPlayer(unit)) then
|
||||
return GetGuildInfo(unit) or nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["guild:brackets"] = "PLAYER_GUILD_UPDATE"
|
||||
ElvUF.Tags.Methods["guild:brackets"] = function(unit)
|
||||
local guildName = GetGuildInfo(unit)
|
||||
|
||||
return guildName and format("<%s>", guildName) or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["guild:translit"] = "UNIT_NAME_UPDATE PLAYER_GUILD_UPDATE"
|
||||
ElvUF.Tags.Methods["guild:translit"] = function(unit)
|
||||
if UnitIsPlayer(unit) then
|
||||
return Translit:Transliterate(GetGuildInfo(unit), translitMark) or nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["guild:brackets:translit"] = "PLAYER_GUILD_UPDATE"
|
||||
ElvUF.Tags.Methods["guild:brackets:translit"] = function(unit)
|
||||
local guildName = Translit:Transliterate(GetGuildInfo(unit), translitMark)
|
||||
|
||||
return guildName and format("<%s>", guildName) or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["target"] = "UNIT_TARGET"
|
||||
ElvUF.Tags.Methods["target"] = function(unit)
|
||||
local targetName = UnitName(unit.."target")
|
||||
return targetName or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["target:translit"] = "UNIT_TARGET"
|
||||
ElvUF.Tags.Methods["target:translit"] = function(unit)
|
||||
local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
|
||||
return targetName or nil
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["guild:rank"] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods["guild:rank"] = function(unit)
|
||||
if (UnitIsPlayer(unit)) then
|
||||
return select(2, GetGuildInfo(unit)) or ""
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["arena:number"] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods["arena:number"] = function(unit)
|
||||
local _, instanceType = GetInstanceInfo()
|
||||
if instanceType == "arena" then
|
||||
for i = 1, 5 do
|
||||
if UnitIsUnit(unit, "arena"..i) then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["class"] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods["class"] = function(unit)
|
||||
return UnitClass(unit)
|
||||
end
|
||||
|
||||
ElvUF.Tags.Events["name:title"] = "UNIT_NAME_UPDATE"
|
||||
ElvUF.Tags.Methods["name:title"] = function(unit)
|
||||
if UnitIsPlayer(unit) then
|
||||
return UnitPVPName(unit)
|
||||
end
|
||||
end
|
||||
E.TagInfo = {
|
||||
--Colors
|
||||
["namecolor"] = {category = "Colors", description = "Colors names by player class or NPC reaction"},
|
||||
["powercolor"] = {category = "Colors", description = "Colors the power text based upon its type"},
|
||||
["energycolor"] = {category = "Colors", description = "Colors the energy text based upon its type"},
|
||||
["ragecolor"] = {category = "Colors", description = "Colors the rage text based upon its type"},
|
||||
["difficultycolor"] = {category = "Colors", description = "Colors the following tags by difficulty, red for impossible, orange for hard, green for easy"},
|
||||
["healthcolor"] = {category = "Colors", description = "Changes color of health text, depending on the unit's current health"},
|
||||
["threatcolor"] = {category = "Colors", description = "Changes color of health, depending on the unit's threat situation"},
|
||||
["classificationcolor"] = {category = "Colors", description = "Changes color of health, depending on the unit's classification"},
|
||||
--Classification
|
||||
["classification"] = {category = "Classification", description = "Displays the unit's classification (e.g. 'ELITE' and 'RARE')"},
|
||||
["shortclassification"] = {category = "Classification", description = "Displays the unit's classification in short form (e.g. '+' for ELITE and 'R' for RARE)"},
|
||||
["rare"] = {category = "Classification", description = "Displays 'Rare' when the unit is a rare or rareelite"},
|
||||
--Guild
|
||||
["guild"] = {category = "Guild", description = "Displays the guild name"},
|
||||
["guild:brackets"] = {category = "Guild", description = "Displays the guild name with < > brackets (e.g. <GUILD>)"},
|
||||
["guild:brackets:translit"] = {category = "Guild", description = "Displays the guild name with < > and transliteration (e.g. <GUILD>)"},
|
||||
["guild:rank"] = {category = "Guild", description = "Displays the guild rank"},
|
||||
["guild:translit"] = {category = "Guild", description = "Displays the guild name with transliteration for cyrillic letters"},
|
||||
--Health
|
||||
["curhp"] = {category = "Health", description = "Displays the current HP without decimals"},
|
||||
["perhp"] = {category = "Health", description = "Displays percentage HP without decimals"},
|
||||
["maxhp"] = {category = "Health", description = "Displays max HP without decimals"},
|
||||
["deficit:name"] = {category = "Health", description = "Displays the health as a deficit and the name at full health"},
|
||||
["health:current"] = {category = "Health", description = "Displays the current health of the unit"},
|
||||
["health:current-max"] = {category = "Health", description = "Displays the current and maximum health of the unit, separated by a dash"},
|
||||
["health:current-max-nostatus"] = {category = "Health", description = "Displays the current and maximum health of the unit, separated by a dash, without status"},
|
||||
["health:current-max-percent"] = {category = "Health", description = "Displays the current and max hp of the unit, separated by a dash (% when not full hp)"},
|
||||
["health:current-max-percent-nostatus"] = {category = "Health", description = "Displays the current and max hp of the unit, separated by a dash (% when not full hp), without status"},
|
||||
["health:current-nostatus"] = {category = "Health", description = "Displays the current health of the unit, without status"},
|
||||
["health:current-percent"] = {category = "Health", description = "Displays the current hp of the unit (% when not full hp)"},
|
||||
["health:current-percent-nostatus"] = {category = "Health", description = "Displays the current hp of the unit (% when not full hp), without status"},
|
||||
["health:deficit"] = {category = "Health", description = "Displays the health of the unit as a deficit (Total Health - Current Health = -Deficit)"},
|
||||
["health:deficit-nostatus"] = {category = "Health", description = "Displays the health of the unit as a deficit, without status"},
|
||||
["health:deficit-percent:name"] = {category = "Health", description = "Displays the health deficit as a percentage and the full name of the unit"},
|
||||
["health:deficit-percent:name-long"] = {category = "Health", description = "Displays the health deficit as a percentage and the name of the unit (limited to 20 letters)"},
|
||||
["health:deficit-percent:name-medium"] = {category = "Health", description = "Displays the health deficit as a percentage and the name of the unit (limited to 15 letters)"},
|
||||
["health:deficit-percent:name-short"] = {category = "Health", description = "Displays the health deficit as a percentage and the name of the unit (limited to 10 letters)"},
|
||||
["health:deficit-percent:name-veryshort"] = {category = "Health", description = "Displays the health deficit as a percentage and the name of the unit (limited to 5 letters)"},
|
||||
["health:max"] = {category = "Health", description = "Displays the maximum health of the unit"},
|
||||
["health:percent"] = {category = "Health", description = "Displays the current health of the unit as a percentage"},
|
||||
["health:percent-nostatus"] = {category = "Health", description = "Displays the unit's current health as a percentage, without status"},
|
||||
["missinghp"] = {category = "Health", description = "Displays the missing health of the unit in whole numbers, when not at full health"},
|
||||
--Level
|
||||
["smartlevel"] = {category = "Level", description = "Only display the unit's level if it is not the same as yours"},
|
||||
["level"] = {category = "Level", description = "Displays the level of the unit"},
|
||||
--Mana
|
||||
["mana:current"] = {category = "Mana", description = "Displays the unit's current amount of mana (e.g. 97200)"},
|
||||
["mana:current-percent"] = {category = "Mana", description = "Displays the current amount of mana as a whole number and a percentage, separated by a dash"},
|
||||
["mana:current-max"] = {category = "Mana", description = "Displays the current mana and max mana, separated by a dash"},
|
||||
["mana:current-max-percent"] = {category = "Mana", description = "Displays the current mana and max mana, separated by a dash (% when not full power)"},
|
||||
["mana:percent"] = {category = "Mana", description = "Displays the mana of the unit as a percentage value"},
|
||||
["mana:max"] = {category = "Mana", description = "Displays the unit's maximum mana"},
|
||||
["mana:deficit"] = {category = "Mana", description = "Displays the mana deficit (Total Mana - Current Mana = -Deficit)"},
|
||||
["curmana"] = {category = "Mana", description = "Displays the current mana without decimals"},
|
||||
["maxmana"] = {category = "Mana", description = "Displays the max amount of mana the unit can have"},
|
||||
--Names
|
||||
["name"] = {category = "Names", description = "Displays the full name of the unit without any letter limitation"},
|
||||
["name:veryshort"] = {category = "Names", description = "Displays the name of the unit (limited to 5 letters)"},
|
||||
["name:short"] = {category = "Names", description = "Displays the name of the unit (limited to 10 letters)"},
|
||||
["name:medium"] = {category = "Names", description = "Displays the name of the unit (limited to 15 letters)"},
|
||||
["name:long"] = {category = "Names", description = "Displays the name of the unit (limited to 20 letters)"},
|
||||
["name:veryshort:translit"] = {category = "Names", description = "Displays the name of the unit with transliteration for cyrillic letters (limited to 5 letters)"},
|
||||
["name:short:translit"] = {category = "Names", description = "Displays the name of the unit with transliteration for cyrillic letters (limited to 10 letters)"},
|
||||
["name:medium:translit"] = {category = "Names", description = "Displays the name of the unit with transliteration for cyrillic letters (limited to 15 letters)"},
|
||||
["name:long:translit"] = {category = "Names", description = "Displays the name of the unit with transliteration for cyrillic letters (limited to 20 letters)"},
|
||||
["name:abbrev"] = {category = "Names", description = "Displays the name of the unit with abbreviation (e.g. 'Shadowfury Witch Doctor' becomes 'S. W. Doctor')"},
|
||||
["name:abbrev:veryshort"] = {category = "Names", description = "Displays the name of the unit with abbreviation (limited to 5 letters)"},
|
||||
["name:abbrev:short"] = {category = "Names", description = "Displays the name of the unit with abbreviation (limited to 10 letters)"},
|
||||
["name:abbrev:medium"] = {category = "Names", description = "Displays the name of the unit with abbreviation (limited to 15 letters)"},
|
||||
["name:abbrev:long"] = {category = "Names", description = "Displays the name of the unit with abbreviation (limited to 20 letters)"},
|
||||
["name:veryshort:status"] = {category = "Names", description = "Replace the name of the unit with 'DEAD' or 'OFFLINE' if applicable (limited to 5 letters)"},
|
||||
["name:short:status"] = {category = "Names", description = "Replace the name of the unit with 'DEAD' or 'OFFLINE' if applicable (limited to 10 letters)"},
|
||||
["name:medium:status"] = {category = "Names", description = "Replace the name of the unit with 'DEAD' or 'OFFLINE' if applicable (limited to 15 letters)"},
|
||||
["name:long:status"] = {category = "Names", description = "Replace the name of the unit with 'DEAD' or 'OFFLINE' if applicable (limited to 20 letters)"},
|
||||
["name:title"] = {category = "Names", description = "Displays player name and title"},
|
||||
--Party and Raid
|
||||
["group"] = {category = "Party and Raid", description = "Displays the group number the unit is in ('1' - '8')"},
|
||||
["leader"] = {category = "Party and Raid", description = "Displays 'L' if the unit is the group/raid leader"},
|
||||
["leaderlong"] = {category = "Party and Raid", description = "Displays 'Leader' if the unit is the group/raid leader"},
|
||||
--Power
|
||||
["power:current"] = {category = "Power", description = "Displays the unit's current amount of power"},
|
||||
["power:current-percent"] = {category = "Power", description = "Displays the current power and power as a percentage, separated by a dash"},
|
||||
["power:current-max"] = {category = "Power", description = "Displays the current power and max power, separated by a dash"},
|
||||
["power:current-max-percent"] = {category = "Power", description = "Displays the current power and max power, separated by a dash (% when not full power)"},
|
||||
["power:percent"] = {category = "Power", description = "Displays the unit's power as a percentage"},
|
||||
["power:max"] = {category = "Power", description = "Displays the unit's maximum power"},
|
||||
["power:deficit"] = {category = "Power", description = "Displays the power as a deficit (Total Power - Current Power = -Deficit)"},
|
||||
["curpp"] = {category = "Power", description = "Displays the unit's current power without decimals"},
|
||||
["perpp"] = {category = "Power", description = "Displays the unit's percentage power without decimals "},
|
||||
["maxpp"] = {category = "Power", description = "Displays the max amount of power of the unit in whole numbers without decimals"},
|
||||
["missingpp"] = {category = "Power", description = "Displays the missing power of the unit in whole numbers when not at full power"},
|
||||
--Energy
|
||||
["energy:current"] = {category = "Energy", description = "Displays the unit's current amount of energy"},
|
||||
["energy:current-percent"] = {category = "Energy", description = "Displays the current energy and energy as a percentage, separated by a dash"},
|
||||
["energy:current-max"] = {category = "Energy", description = "Displays the current energy and max energy, separated by a dash"},
|
||||
["energy:current-max-percent"] = {category = "Energy", description = "Displays the current energy and max energy, separated by a dash (% when not full energy)"},
|
||||
["energy:percent"] = {category = "Energy", description = "Displays the unit's energy as a percentage"},
|
||||
["energy:max"] = {category = "Energy", description = "Displays the unit's maximum energy"},
|
||||
["energy:deficit"] = {category = "Energy", description = "Displays the energy as a deficit (Total Energy - Current Energy = -Deficit)"},
|
||||
--Rage
|
||||
["rage:current"] = {category = "Rage", description = "Displays the unit's current amount of rage"},
|
||||
["rage:current-percent"] = {category = "Rage", description = "Displays the current rage and rage as a percentage, separated by a dash"},
|
||||
["rage:current-max"] = {category = "Rage", description = "Displays the current rage and max rage, separated by a dash"},
|
||||
["rage:current-max-percent"] = {category = "Rage", description = "Displays the current rage and max rage, separated by a dash (% when not full rage)"},
|
||||
["rage:percent"] = {category = "Rage", description = "Displays the unit's rage as a percentage"},
|
||||
["rage:max"] = {category = "Rage", description = "Displays the unit's maximum rage"},
|
||||
["rage:deficit"] = {category = "Rage", description = "Displays the rage as a deficit (Total Rage - Current Rage = -Deficit)"},
|
||||
--Realm
|
||||
["realm"] = {category = "Realm", description = "Displays the server name"},
|
||||
["realm:translit"] = {category = "Realm", description = "Displays the server name with transliteration for cyrillic letters"},
|
||||
["realm:dash"] = {category = "Realm", description = "Displays the server name with a dash in front (e.g. -Realm)"},
|
||||
["realm:dash:translit"] = {category = "Realm", description = "Displays the server name with transliteration for cyrillic letters and a dash in front"},
|
||||
--Status
|
||||
["status"] = {category = "Status", description = "Displays zzz, dead, ghost, offline"},
|
||||
["statustimer"] = {category = "Status", description = "Displays a timer for how long a unit has had the status (e.g 'DEAD - 0:34')"},
|
||||
["afk"] = {category = "Status", description = "Displays <AFK> if the Unit is afk"},
|
||||
["dead"] = {category = "Status", description = "Displays <DEAD> if the unit is dead"},
|
||||
["resting"] = {category = "Status", description = "Displays zzz if the unit is dead"},
|
||||
["pvp"] = {category = "Status", description = "Displays 'PvP' if the unit is pvp flagged"},
|
||||
["offline"] = {category = "Status", description = "Displays 'OFFLINE' if the unit is disconnected"},
|
||||
--Target
|
||||
["target"] = {category = "Target", description = "Displays the current target of the unit"},
|
||||
["target:veryshort"] = {category = "Target", description = "Displays the current target of the unit (limited to 5 letters)"},
|
||||
["target:short"] = {category = "Target", description = "Displays the current target of the unit (limited to 10 letters)"},
|
||||
["target:medium"] = {category = "Target", description = "Displays the current target of the unit (limited to 15 letters)"},
|
||||
["target:long"] = {category = "Target", description = "Displays the current target of the unit (limited to 20 letters)"},
|
||||
["target:translit"] = {category = "Target", description = "Displays the current target of the unit with transliteration for cyrillic letters"},
|
||||
["target:veryshort:translit"] = {category = "Target", description = "Displays the current target of the unit with transliteration for cyrillic letters (limited to 5 letters)"},
|
||||
["target:short:translit"] = {category = "Target", description = "Displays the current target of the unit with transliteration for cyrillic letters (limited to 10 letters)"},
|
||||
["target:medium:translit"] = {category = "Target", description = "Displays the current target of the unit with transliteration for cyrillic letters (limited to 15 letters)"},
|
||||
["target:long:translit"] = {category = "Target", description = "Displays the current target of the unit with transliteration for cyrillic letters (limited to 20 letters)"},
|
||||
--Threat
|
||||
["threat"] = {category = "Threat", description = "Displays the current threat"},
|
||||
["threat:percent"] = {category = "Threat", description = "Displays the current threat as a percent"},
|
||||
["threat:current"] = {category = "Threat", description = "Displays the current threat as a value"},
|
||||
--Miscellaneous
|
||||
["smartclass"] = {category = "Miscellaneous", description = "Displays the player's class or creature's type"},
|
||||
["class"] = {category = "Miscellaneous", description = "Displays the class of the unit, if that unit is a player"},
|
||||
["difficulty"] = {category = "Miscellaneous", description = "Changes color of the next tag based on how difficult the unit is compared to the players level"},
|
||||
["faction"] = {category = "Miscellaneous", description = "Displays 'Aliance' or 'Horde'"},
|
||||
["plus"] = {category = "Miscellaneous", description = "Displays the character '+' if the unit is an elite or rare-elite"},
|
||||
["arena:number"] = {category = "Miscellaneous", description = "Displays the arena number 1-5"},
|
||||
}
|
||||
|
||||
function E:AddTagInfo(tagName, category, description, order)
|
||||
if order then order = tonumber(order) + 10 end
|
||||
|
||||
E.TagInfo[tagName] = E.TagInfo[tagName] or {}
|
||||
E.TagInfo[tagName].category = category or "Miscellaneous"
|
||||
E.TagInfo[tagName].description = description or ""
|
||||
E.TagInfo[tagName].order = order or nil
|
||||
end
|
||||
@@ -0,0 +1,346 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local LSM = E.Libs.LSM
|
||||
|
||||
--Lua functions
|
||||
local _G = _G
|
||||
local unpack, type, select, getmetatable, assert = unpack, type, select, getmetatable, assert
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
|
||||
local backdropr, backdropg, backdropb, backdropa, borderr, borderg, borderb = 0, 0, 0, 1, 0, 0, 0
|
||||
local function GetTemplate(template, isUnitFrameElement)
|
||||
backdropa = 1
|
||||
|
||||
if template == "ClassColor" then
|
||||
local color = E.media.herocolor
|
||||
borderr, borderg, borderb = color.r, color.g, color.b
|
||||
backdropr, backdropg, backdropb = unpack(E.media.backdropcolor)
|
||||
elseif template == "Transparent" then
|
||||
borderr, borderg, borderb = unpack(isUnitFrameElement and E.media.unitframeBorderColor or E.media.bordercolor)
|
||||
backdropr, backdropg, backdropb, backdropa = unpack(E.media.backdropfadecolor)
|
||||
else
|
||||
borderr, borderg, borderb = unpack(isUnitFrameElement and E.media.unitframeBorderColor or E.media.bordercolor)
|
||||
backdropr, backdropg, backdropb = unpack(E.media.backdropcolor)
|
||||
end
|
||||
end
|
||||
|
||||
local function Size(frame, width, height)
|
||||
assert(width)
|
||||
frame:SetSize(E:Scale(width), E:Scale(height or width))
|
||||
end
|
||||
|
||||
local function Width(frame, width)
|
||||
assert(width)
|
||||
frame:SetWidth(E:Scale(width))
|
||||
end
|
||||
|
||||
local function Height(frame, height)
|
||||
assert(height)
|
||||
frame:SetHeight(E:Scale(height))
|
||||
end
|
||||
|
||||
local function Point(obj, arg1, arg2, arg3, arg4, arg5)
|
||||
if arg2 == nil then arg2 = obj:GetParent() end
|
||||
|
||||
if type(arg2) == "number" then arg2 = E:Scale(arg2) end
|
||||
if type(arg3) == "number" then arg3 = E:Scale(arg3) end
|
||||
if type(arg4) == "number" then arg4 = E:Scale(arg4) end
|
||||
if type(arg5) == "number" then arg5 = E:Scale(arg5) end
|
||||
|
||||
obj:SetPoint(arg1, arg2, arg3, arg4, arg5)
|
||||
end
|
||||
|
||||
local function SetOutside(obj, anchor, xOffset, yOffset, anchor2)
|
||||
xOffset = xOffset or E.Border
|
||||
yOffset = yOffset or E.Border
|
||||
anchor = anchor or obj:GetParent()
|
||||
|
||||
assert(anchor)
|
||||
if obj:GetPoint() then
|
||||
obj:ClearAllPoints()
|
||||
end
|
||||
|
||||
obj:Point("TOPLEFT", anchor, "TOPLEFT", -xOffset, yOffset)
|
||||
obj:Point("BOTTOMRIGHT", anchor2 or anchor, "BOTTOMRIGHT", xOffset, -yOffset)
|
||||
end
|
||||
|
||||
local function SetInside(obj, anchor, xOffset, yOffset, anchor2)
|
||||
xOffset = xOffset or E.Border
|
||||
yOffset = yOffset or E.Border
|
||||
anchor = anchor or obj:GetParent()
|
||||
|
||||
assert(anchor)
|
||||
if obj:GetPoint() then
|
||||
obj:ClearAllPoints()
|
||||
end
|
||||
|
||||
obj:Point("TOPLEFT", anchor, "TOPLEFT", xOffset, -yOffset)
|
||||
obj:Point("BOTTOMRIGHT", anchor2 or anchor, "BOTTOMRIGHT", -xOffset, yOffset)
|
||||
end
|
||||
|
||||
local function SetTemplate(frame, template, glossTex, ignoreUpdates, forcePixelMode, isUnitFrameElement)
|
||||
GetTemplate(template, isUnitFrameElement)
|
||||
|
||||
frame.template = template or "Default"
|
||||
if glossTex then frame.glossTex = glossTex end
|
||||
if ignoreUpdates then frame.ignoreUpdates = ignoreUpdates end
|
||||
if forcePixelMode then frame.forcePixelMode = forcePixelMode end
|
||||
if isUnitFrameElement then frame.isUnitFrameElement = isUnitFrameElement end
|
||||
|
||||
local bgFile = glossTex and E.media.glossTex or E.media.blankTex
|
||||
|
||||
if template ~= "NoBackdrop" then
|
||||
frame:SetBackdrop({
|
||||
bgFile = bgFile,
|
||||
edgeFile = E.media.blankTex,
|
||||
tile = false, tileSize = 0, edgeSize = E.mult,
|
||||
insets = {left = 0, right = 0, top = 0, bottom = 0}
|
||||
})
|
||||
|
||||
frame:SetBackdropColor(backdropr, backdropg, backdropb, backdropa)
|
||||
|
||||
if not E.PixelMode and not frame.forcePixelMode then
|
||||
if not frame.iborder then
|
||||
local border = CreateFrame("Frame", nil, frame)
|
||||
border:SetInside(frame, E.mult, E.mult)
|
||||
border:SetBackdrop({
|
||||
edgeFile = E.media.blankTex,
|
||||
edgeSize = E.mult,
|
||||
insets = {left = -E.mult, right = -E.mult, top = -E.mult, bottom = -E.mult}
|
||||
})
|
||||
border:SetBackdropBorderColor(0, 0, 0, 1)
|
||||
frame.iborder = border
|
||||
end
|
||||
|
||||
if not frame.oborder then
|
||||
local border = CreateFrame("Frame", nil, frame)
|
||||
border:SetOutside(frame, E.mult, E.mult)
|
||||
border:SetFrameLevel(frame:GetFrameLevel() + 1)
|
||||
border:SetBackdrop({
|
||||
edgeFile = E.media.blankTex,
|
||||
edgeSize = E.mult,
|
||||
insets = {left = E.mult, right = E.mult, top = E.mult, bottom = E.mult}
|
||||
})
|
||||
border:SetBackdropBorderColor(0, 0, 0, 1)
|
||||
frame.oborder = border
|
||||
end
|
||||
end
|
||||
else
|
||||
frame:SetBackdrop(nil)
|
||||
end
|
||||
frame:SetBackdropBorderColor(borderr, borderg, borderb)
|
||||
|
||||
if not frame.ignoreUpdates then
|
||||
if frame.isUnitFrameElement then
|
||||
E.unitFrameElements[frame] = true
|
||||
else
|
||||
E.frames[frame] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function CreateBackdrop(frame, template, glossTex, ignoreUpdates, forcePixelMode, isUnitFrameElement)
|
||||
if not template then template = "Default" end
|
||||
|
||||
local parent = (frame.IsObjectType and frame:IsObjectType("Texture") and frame:GetParent()) or frame
|
||||
local backdrop = frame.backdrop or CreateFrame("Frame", nil, parent)
|
||||
if not frame.backdrop then frame.backdrop = backdrop end
|
||||
|
||||
if frame.forcePixelMode or forcePixelMode then
|
||||
backdrop:SetOutside(frame, E.mult, E.mult)
|
||||
else
|
||||
backdrop:SetOutside(frame)
|
||||
end
|
||||
|
||||
backdrop:SetTemplate(template, glossTex, ignoreUpdates, forcePixelMode, isUnitFrameElement)
|
||||
|
||||
local frameLevel = parent.GetFrameLevel and parent:GetFrameLevel()
|
||||
local frameLevelMinusOne = frameLevel and (frameLevel - 1)
|
||||
if frameLevelMinusOne and (frameLevelMinusOne >= 0) then
|
||||
backdrop:SetFrameLevel(frameLevelMinusOne)
|
||||
else
|
||||
backdrop:SetFrameLevel(0)
|
||||
end
|
||||
end
|
||||
|
||||
local function CreateShadow(frame, size)
|
||||
if frame.shadow then return end
|
||||
|
||||
backdropr, backdropg, backdropb, borderr, borderg, borderb = 0, 0, 0, 0, 0, 0
|
||||
|
||||
local shadow = CreateFrame("Frame", nil, frame)
|
||||
shadow:SetFrameLevel(1)
|
||||
shadow:SetFrameStrata(frame:GetFrameStrata())
|
||||
shadow:SetOutside(frame, size or 3, size or 3)
|
||||
shadow:SetBackdrop({edgeFile = LSM:Fetch("border", "ElvUI GlowBorder"), edgeSize = E:Scale(size or 3)})
|
||||
shadow:SetBackdropColor(backdropr, backdropg, backdropb, 0)
|
||||
shadow:SetBackdropBorderColor(borderr, borderg, borderb, 0.9)
|
||||
frame.shadow = shadow
|
||||
end
|
||||
|
||||
local function Kill(object)
|
||||
if object.UnregisterAllEvents then
|
||||
object:UnregisterAllEvents()
|
||||
object:SetParent(E.HiddenFrame)
|
||||
else
|
||||
object.Show = object.Hide
|
||||
end
|
||||
|
||||
object:Hide()
|
||||
end
|
||||
|
||||
local function StripTextures(object, kill, alpha)
|
||||
if object:IsObjectType("Texture") then
|
||||
if kill then
|
||||
object:Kill()
|
||||
elseif alpha then
|
||||
object:SetAlpha(0)
|
||||
else
|
||||
object:SetTexture()
|
||||
end
|
||||
else
|
||||
if object.GetNumRegions then
|
||||
for i = 1, object:GetNumRegions() do
|
||||
local region = select(i, object:GetRegions())
|
||||
if region and region.IsObjectType and region:IsObjectType("Texture") then
|
||||
if kill then
|
||||
region:Kill()
|
||||
elseif alpha then
|
||||
region:SetAlpha(0)
|
||||
else
|
||||
region:SetTexture()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function FontTemplate(fs, font, fontSize, fontStyle)
|
||||
fs.font = font
|
||||
fs.fontSize = fontSize
|
||||
fs.fontStyle = fontStyle
|
||||
|
||||
font = font or LSM:Fetch("font", E.db.general.font)
|
||||
fontSize = fontSize or E.db.general.fontSize
|
||||
fontStyle = fontStyle or E.db.general.fontStyle
|
||||
|
||||
if fontStyle == "OUTLINE" and E.db.general.font == "Homespun" and (fontSize > 10 and not fs.fontSize) then
|
||||
fontSize, fontStyle = 10, "MONOCHROMEOUTLINE"
|
||||
end
|
||||
|
||||
fs:SetFont(font, fontSize, fontStyle)
|
||||
|
||||
if fontStyle == "NONE" then
|
||||
local s = E.mult or 1
|
||||
fs:SetShadowOffset(s, -s/2)
|
||||
fs:SetShadowColor(0, 0, 0, 1)
|
||||
else
|
||||
fs:SetShadowOffset(0, 0)
|
||||
fs:SetShadowColor(0, 0, 0, 0)
|
||||
end
|
||||
|
||||
E.texts[fs] = true
|
||||
end
|
||||
|
||||
local function StyleButton(button, noHover, noPushed, noChecked)
|
||||
if button.SetHighlightTexture and not button.hover and not noHover then
|
||||
local hover = button:CreateTexture()
|
||||
hover:SetInside()
|
||||
hover:SetTexture(1, 1, 1, 0.3)
|
||||
button:SetHighlightTexture(hover)
|
||||
button.hover = hover
|
||||
end
|
||||
|
||||
if button.SetPushedTexture and not button.pushed and not noPushed then
|
||||
local pushed = button:CreateTexture()
|
||||
pushed:SetInside()
|
||||
pushed:SetTexture(0.9, 0.8, 0.1, 0.3)
|
||||
button:SetPushedTexture(pushed)
|
||||
button.pushed = pushed
|
||||
end
|
||||
|
||||
if button.SetCheckedTexture and not button.checked and not noChecked then
|
||||
local checked = button:CreateTexture()
|
||||
checked:SetInside()
|
||||
checked:SetTexture(1, 1, 1, 0.3)
|
||||
button:SetCheckedTexture(checked)
|
||||
button.checked = checked
|
||||
end
|
||||
|
||||
local name = button.GetName and button:GetName()
|
||||
local cooldown = name and _G[name.."Cooldown"]
|
||||
if cooldown then
|
||||
cooldown:ClearAllPoints()
|
||||
cooldown:SetInside()
|
||||
end
|
||||
end
|
||||
|
||||
local CreateCloseButton
|
||||
do
|
||||
local CloseButtonOnClick = function(btn) btn:GetParent():Hide() end
|
||||
local CloseButtonOnEnter = function(btn) if btn.Texture then btn.Texture:SetVertexColor(unpack(E.media.rgbvaluecolor)) end end
|
||||
local CloseButtonOnLeave = function(btn) if btn.Texture then btn.Texture:SetVertexColor(1, 1, 1) end end
|
||||
CreateCloseButton = function(frame, size, offset, texture, backdrop)
|
||||
if frame.CloseButton then return end
|
||||
|
||||
local CloseButton = CreateFrame("Button", nil, frame)
|
||||
CloseButton:Size(size or 16)
|
||||
CloseButton:Point("TOPRIGHT", offset or -6, offset or -6)
|
||||
if backdrop then CloseButton:CreateBackdrop(nil, true) end
|
||||
|
||||
CloseButton.Texture = CloseButton:CreateTexture(nil, "OVERLAY")
|
||||
CloseButton.Texture:SetAllPoints()
|
||||
CloseButton.Texture:SetTexture(texture or E.Media.Textures.Close)
|
||||
|
||||
CloseButton:SetScript("OnClick", CloseButtonOnClick)
|
||||
CloseButton:SetScript("OnEnter", CloseButtonOnEnter)
|
||||
CloseButton:SetScript("OnLeave", CloseButtonOnLeave)
|
||||
|
||||
frame.CloseButton = CloseButton
|
||||
end
|
||||
end
|
||||
|
||||
local function GetNamedChild(frame, childName, index)
|
||||
local name = frame and frame.GetName and frame:GetName()
|
||||
if not name or not childName then return nil end
|
||||
return _G[name..childName..(index or "")]
|
||||
end
|
||||
|
||||
local function addapi(object)
|
||||
local mt = getmetatable(object).__index
|
||||
if not object.Size then mt.Size = Size end
|
||||
if not object.Point then mt.Point = Point end
|
||||
if not object.SetOutside then mt.SetOutside = SetOutside end
|
||||
if not object.SetInside then mt.SetInside = SetInside end
|
||||
if not object.SetTemplate then mt.SetTemplate = SetTemplate end
|
||||
if not object.CreateBackdrop then mt.CreateBackdrop = CreateBackdrop end
|
||||
if not object.CreateShadow then mt.CreateShadow = CreateShadow end
|
||||
if not object.Kill then mt.Kill = Kill end
|
||||
if not object.Width then mt.Width = Width end
|
||||
if not object.Height then mt.Height = Height end
|
||||
if not object.FontTemplate then mt.FontTemplate = FontTemplate end
|
||||
if not object.StripTextures then mt.StripTextures = StripTextures end
|
||||
if not object.StyleButton then mt.StyleButton = StyleButton end
|
||||
if not object.CreateCloseButton then mt.CreateCloseButton = CreateCloseButton end
|
||||
if not object.GetNamedChild then mt.GetNamedChild = GetNamedChild end
|
||||
end
|
||||
|
||||
local handled = {["Frame"] = true}
|
||||
local object = CreateFrame("Frame")
|
||||
addapi(object)
|
||||
addapi(object:CreateTexture())
|
||||
addapi(object:CreateFontString())
|
||||
|
||||
object = EnumerateFrames()
|
||||
while object do
|
||||
if not handled[object:GetObjectType()] then
|
||||
addapi(object)
|
||||
handled[object:GetObjectType()] = true
|
||||
end
|
||||
|
||||
object = EnumerateFrames(object)
|
||||
end
|
||||
|
||||
--Add API to `CreateFont` objects without actually creating one
|
||||
addapi(GameFontNormal)
|
||||
@@ -0,0 +1,120 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local Skins = E:GetModule("Skins")
|
||||
|
||||
--Lua functions
|
||||
local _G = _G
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local DISABLE = DISABLE
|
||||
local HIDE = HIDE
|
||||
|
||||
E.TutorialList = {
|
||||
L["For technical support visit us at https://github.com/ElvUI-WotLK."],
|
||||
L["You can toggle the microbar by using your middle mouse button on the minimap you can also accomplish this by enabling the actual microbar located in the actionbar settings."],
|
||||
L["A raid marker feature is available by pressing Escape -> Keybinds scroll to the bottom under ElvUI and setting a keybind for the raid marker."],
|
||||
L["You can set your keybinds quickly by typing /kb."],
|
||||
L["The focus unit can be set by typing /focus when you are targeting the unit you want to focus. It is recommended you make a macro to do this."],
|
||||
L["ElvUI has a dual spec feature which allows you to load different profiles based on your current spec on the fly. You can enable this from the profiles tab."],
|
||||
L["You can access copy chat and chat menu functions by mouse over the top right corner of chat panel and left/right click on the button that will appear."],
|
||||
L["If you are experiencing issues with ElvUI try disabling all your addons except ElvUI, remember ElvUI is a full UI replacement addon, you cannot run two addons that do the same thing."],
|
||||
L["If you accidently remove a chat frame you can always go the in-game configuration menu, press install, go to the chat portion and reset them."],
|
||||
L["To setup which channels appear in which chat frame, right click the chat tab and go to settings."],
|
||||
L["You can use the /resetui command to reset all of your movers. You can also use the command to reset a specific mover, /resetui <mover name>.\nExample: /resetui Player Frame"],
|
||||
L["To move abilities on the actionbars by default hold shift + drag. You can change the modifier key from the actionbar options menu."],
|
||||
L["You can see someones average item level of their gear by holding shift and mousing over them. It should appear inside the tooltip."]
|
||||
}
|
||||
|
||||
function E:SetNextTutorial()
|
||||
self.db.currentTutorial = self.db.currentTutorial or 0
|
||||
self.db.currentTutorial = self.db.currentTutorial + 1
|
||||
|
||||
if self.db.currentTutorial > #E.TutorialList then
|
||||
self.db.currentTutorial = 1
|
||||
end
|
||||
|
||||
ElvUITutorialWindow.desc:SetText(E.TutorialList[self.db.currentTutorial])
|
||||
end
|
||||
|
||||
function E:SetPrevTutorial()
|
||||
self.db.currentTutorial = self.db.currentTutorial or 0
|
||||
self.db.currentTutorial = self.db.currentTutorial - 1
|
||||
|
||||
if self.db.currentTutorial <= 0 then
|
||||
self.db.currentTutorial = #E.TutorialList
|
||||
end
|
||||
|
||||
ElvUITutorialWindow.desc:SetText(E.TutorialList[self.db.currentTutorial])
|
||||
end
|
||||
|
||||
function E:SpawnTutorialFrame()
|
||||
local f = CreateFrame("Frame", "ElvUITutorialWindow", E.UIParent)
|
||||
f:SetFrameStrata("DIALOG")
|
||||
f:SetToplevel(true)
|
||||
f:SetClampedToScreen(true)
|
||||
f:Width(360)
|
||||
f:Height(110)
|
||||
f:SetTemplate("Transparent")
|
||||
f:Hide()
|
||||
|
||||
local header = CreateFrame("Button", nil, f)
|
||||
header:SetTemplate("Default", true)
|
||||
header:Width(120)
|
||||
header:Height(25)
|
||||
header:Point("CENTER", f, "TOP")
|
||||
header:SetFrameLevel(header:GetFrameLevel() + 2)
|
||||
|
||||
local title = header:CreateFontString("OVERLAY")
|
||||
title:FontTemplate()
|
||||
title:Point("CENTER", header, "CENTER")
|
||||
title:SetText("ElvUI")
|
||||
|
||||
local desc = f:CreateFontString("ARTWORK")
|
||||
desc:SetFontObject("GameFontHighlight")
|
||||
desc:SetJustifyV("TOP")
|
||||
desc:SetJustifyH("LEFT")
|
||||
desc:Point("TOPLEFT", 18, -32)
|
||||
desc:Point("BOTTOMRIGHT", -18, 30)
|
||||
f.desc = desc
|
||||
|
||||
f.disableButton = CreateFrame("CheckButton", f:GetName().."DisableButton", f, "OptionsCheckButtonTemplate")
|
||||
_G[f.disableButton:GetName().."Text"]:SetText(DISABLE)
|
||||
f.disableButton:Point("BOTTOMLEFT")
|
||||
Skins:HandleCheckBox(f.disableButton)
|
||||
f.disableButton:SetScript("OnShow", function(self) self:SetChecked(E.db.hideTutorial) end)
|
||||
|
||||
f.disableButton:SetScript("OnClick", function(self) E.db.hideTutorial = self:GetChecked() end)
|
||||
|
||||
f.hideButton = CreateFrame("Button", f:GetName().."HideButton", f, "OptionsButtonTemplate")
|
||||
f.hideButton:Point("BOTTOMRIGHT", -5, 5)
|
||||
Skins:HandleButton(f.hideButton)
|
||||
_G[f.hideButton:GetName().."Text"]:SetText(HIDE)
|
||||
f.hideButton:SetScript("OnClick", function(self) E:StaticPopupSpecial_Hide(self:GetParent()) end)
|
||||
|
||||
f.nextButton = CreateFrame("Button", f:GetName().."NextButton", f, "OptionsButtonTemplate")
|
||||
f.nextButton:Point("RIGHT", f.hideButton, "LEFT", -4, 0)
|
||||
f.nextButton:Width(20)
|
||||
Skins:HandleButton(f.nextButton)
|
||||
_G[f.nextButton:GetName().."Text"]:SetText(">")
|
||||
f.nextButton:SetScript("OnClick", function() E:SetNextTutorial() end)
|
||||
|
||||
f.prevButton = CreateFrame("Button", f:GetName().."PrevButton", f, "OptionsButtonTemplate")
|
||||
f.prevButton:Point("RIGHT", f.nextButton, "LEFT", -4, 0)
|
||||
f.prevButton:Width(20)
|
||||
Skins:HandleButton(f.prevButton)
|
||||
_G[f.prevButton:GetName().."Text"]:SetText("<")
|
||||
f.prevButton:SetScript("OnClick", function() E:SetPrevTutorial() end)
|
||||
|
||||
return f
|
||||
end
|
||||
|
||||
function E:Tutorials(forceShow)
|
||||
if (not forceShow and self.db.hideTutorial) or (not forceShow and not self.private.install_complete) then return end
|
||||
local f = ElvUITutorialWindow
|
||||
if not f then
|
||||
f = E:SpawnTutorialFrame()
|
||||
end
|
||||
|
||||
E:StaticPopupSpecial_Show(f)
|
||||
|
||||
self:SetNextTutorial()
|
||||
end
|
||||
@@ -0,0 +1,280 @@
|
||||
--Lua functions
|
||||
local _G = _G
|
||||
local loadstring = loadstring
|
||||
local pcall = pcall
|
||||
local print = print
|
||||
local select = select
|
||||
local tostring = tostring
|
||||
local type = type
|
||||
local find, format, match = string.find, string.format, string.match
|
||||
local tconcat = table.concat
|
||||
--WoW API / Variables
|
||||
local FrameStackTooltip_Toggle = FrameStackTooltip_Toggle
|
||||
local GetMouseFocus = GetMouseFocus
|
||||
local tostringall = tostringall
|
||||
|
||||
local WorldFrame = WorldFrame
|
||||
|
||||
local DEFAULT_CHAT_FRAME = DEFAULT_CHAT_FRAME
|
||||
local oldAddMessage
|
||||
|
||||
local function printNoTimestamp(...)
|
||||
if oldAddMessage or DEFAULT_CHAT_FRAME.OldAddMessage then
|
||||
if not oldAddMessage then
|
||||
oldAddMessage = DEFAULT_CHAT_FRAME.OldAddMessage
|
||||
end
|
||||
|
||||
if select("#", ...) > 1 then
|
||||
oldAddMessage(DEFAULT_CHAT_FRAME, tconcat({tostringall(...)}, ", "))
|
||||
else
|
||||
oldAddMessage(DEFAULT_CHAT_FRAME, ...)
|
||||
end
|
||||
elseif CHAT_TIMESTAMP_FORMAT then
|
||||
local tsformat = CHAT_TIMESTAMP_FORMAT
|
||||
CHAT_TIMESTAMP_FORMAT = nil
|
||||
print(...)
|
||||
CHAT_TIMESTAMP_FORMAT = tsformat
|
||||
else
|
||||
print(...)
|
||||
end
|
||||
end
|
||||
|
||||
local function updateCopyChat()
|
||||
if CopyChatFrame and CopyChatFrame:IsShown() then
|
||||
CopyChatFrame:Hide()
|
||||
ElvUI[1]:GetModule("Chat"):CopyChat(DEFAULT_CHAT_FRAME)
|
||||
end
|
||||
end
|
||||
|
||||
local function getObject(objName)
|
||||
local obj
|
||||
|
||||
if objName == "" then
|
||||
obj = GetMouseFocus()
|
||||
else
|
||||
obj = _G[objName]
|
||||
|
||||
if not obj then
|
||||
local pass
|
||||
|
||||
if find(objName, "^[%.:]([A-z0-9_]+)") then
|
||||
local _obj = GetMouseFocus()
|
||||
|
||||
if _obj and _obj ~= WorldFrame then
|
||||
local res = match(objName, "^[%.:]([A-z0-9_]+)")
|
||||
|
||||
if res and _obj[res] and _obj:GetName() then
|
||||
objName = format("%s%s", _obj:GetName(), objName)
|
||||
end
|
||||
|
||||
pass = true
|
||||
end
|
||||
elseif find(objName, "[%.()%[%]'\"]") then
|
||||
pass = true
|
||||
end
|
||||
|
||||
if pass then
|
||||
local success, ret = pcall(loadstring(format("return %s", objName)))
|
||||
if success then
|
||||
ret = ret == "string" and _G[ret] or ret
|
||||
|
||||
if type(ret) == "table" and ret.GetName then
|
||||
obj = ret
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if obj then
|
||||
return obj ~= WorldFrame and obj or nil
|
||||
else
|
||||
printNoTimestamp(format("Object |cffFFD100%s|r not found!", objName))
|
||||
end
|
||||
end
|
||||
|
||||
local FrameStackHighlight = CreateFrame("Frame", "FrameStackHighlight")
|
||||
FrameStackHighlight:SetFrameStrata("TOOLTIP")
|
||||
FrameStackHighlight.t = FrameStackHighlight:CreateTexture(nil, "BORDER")
|
||||
FrameStackHighlight.t:SetAllPoints()
|
||||
FrameStackHighlight.t:SetTexture(0, 1, 0, 0.5)
|
||||
|
||||
local FrameStackHitRectHighlight = CreateFrame("Frame", "FrameStackHitRectHighlight")
|
||||
FrameStackHitRectHighlight:SetFrameStrata("TOOLTIP")
|
||||
FrameStackHitRectHighlight.t = FrameStackHitRectHighlight:CreateTexture(nil, "ARTWORK")
|
||||
FrameStackHitRectHighlight.t:SetAllPoints()
|
||||
FrameStackHitRectHighlight.t:SetTexture(0, 0, 1, 0.5)
|
||||
FrameStackHitRectHighlight.t:SetBlendMode("ADD")
|
||||
|
||||
hooksecurefunc("FrameStackTooltip_Toggle", function()
|
||||
if not FrameStackTooltip:IsVisible() then
|
||||
FrameStackHighlight:Hide()
|
||||
FrameStackHitRectHighlight:Hide()
|
||||
end
|
||||
end)
|
||||
|
||||
local _timeSinceLast = 0
|
||||
FrameStackTooltip:HookScript("OnUpdate", function(_, elapsed)
|
||||
_timeSinceLast = _timeSinceLast - elapsed
|
||||
if _timeSinceLast <= 0 then
|
||||
_timeSinceLast = FRAMESTACK_UPDATE_TIME
|
||||
local highlightFrame = GetMouseFocus()
|
||||
|
||||
if highlightFrame and highlightFrame ~= WorldFrame then
|
||||
FrameStackHighlight:ClearAllPoints()
|
||||
FrameStackHighlight:SetPoint("BOTTOMLEFT", highlightFrame)
|
||||
FrameStackHighlight:SetPoint("TOPRIGHT", highlightFrame)
|
||||
FrameStackHighlight:Show()
|
||||
|
||||
local l, r, t, b = highlightFrame:GetHitRectInsets()
|
||||
if l ~= 0 or r ~= 0 or t ~= 0 or b ~= 0 then
|
||||
local scale = highlightFrame:GetEffectiveScale()
|
||||
FrameStackHitRectHighlight:ClearAllPoints()
|
||||
FrameStackHitRectHighlight:SetPoint("TOPLEFT", highlightFrame, l * scale, -t * scale)
|
||||
FrameStackHitRectHighlight:SetPoint("BOTTOMRIGHT", highlightFrame, -r * scale, b * scale)
|
||||
FrameStackHitRectHighlight:Show()
|
||||
else
|
||||
FrameStackHitRectHighlight:Hide()
|
||||
end
|
||||
else
|
||||
FrameStackHighlight:Hide()
|
||||
FrameStackHitRectHighlight:Hide()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
SLASH_FRAME1 = "/frame"
|
||||
SlashCmdList.FRAME = function(frame)
|
||||
frame = getObject(frame)
|
||||
if not frame then return end
|
||||
|
||||
local parent = frame:GetParent()
|
||||
local parentName = parent and parent.GetName and parent:GetName()
|
||||
|
||||
printNoTimestamp("|cffCC0000----------------------------")
|
||||
|
||||
printNoTimestamp(format("Name: |cffFFD100%s|r; ObjectType: |cffFFD100%s|r", frame:GetName() or "nil", frame:GetObjectType()))
|
||||
printNoTimestamp(format("Parent: |cffFFD100%s|r", parentName or (parent and tostring(parent)) or "nil"))
|
||||
|
||||
if frame.GetFrameStrata then
|
||||
printNoTimestamp(format("Strata: |cffFFD100%s|r; FrameLevel: |cffFFD100%d|r", frame:GetFrameStrata(), frame:GetFrameLevel()))
|
||||
else
|
||||
printNoTimestamp(format("DrawLayer: |cffFFD100%s|r", frame:GetDrawLayer()))
|
||||
end
|
||||
|
||||
if frame.GetScale then
|
||||
printNoTimestamp(format("Width: |cffFFD100%.0f|r; Height: |cffFFD100%.0f|r; Scale: |cffFFD100%s|r", frame:GetWidth(), frame:GetHeight(), frame:GetScale()))
|
||||
else
|
||||
printNoTimestamp(format("Width: |cffFFD100%.0f|r; Height: |cffFFD100%.0f|r", frame:GetWidth(), frame:GetHeight()))
|
||||
end
|
||||
|
||||
local point, relativeTo, relativePoint, x, y, relativeName
|
||||
for i = 1, frame:GetNumPoints() do
|
||||
point, relativeTo, relativePoint, x, y = frame:GetPoint(i)
|
||||
relativeName = relativeTo and relativeTo.GetName and (relativeTo:GetName() or tostring(relativeTo)) or "nil"
|
||||
|
||||
if point == relativePoint and relativeTo == parent then
|
||||
printNoTimestamp(format("Point %d: |cffFFD100\"%s\", %.0f, %.0f|r", i, point, x, y))
|
||||
else
|
||||
printNoTimestamp(format("Point %d: |cffFFD100\"%s\", %s, \"%s\", %.0f, %.0f|r", i, point, relativeName, relativePoint, x, y))
|
||||
end
|
||||
end
|
||||
|
||||
printNoTimestamp("|cffCC0000----------------------------")
|
||||
|
||||
updateCopyChat()
|
||||
end
|
||||
|
||||
SLASH_FRAMELIST1 = "/framelist"
|
||||
SlashCmdList.FRAMELIST = function(showHidden)
|
||||
if not FrameStackTooltip then
|
||||
UIParentLoadAddOn("Blizzard_DebugTools")
|
||||
end
|
||||
|
||||
local isPreviouslyShown = FrameStackTooltip:IsShown()
|
||||
if not isPreviouslyShown then
|
||||
if showHidden == "true" then
|
||||
FrameStackTooltip_Toggle(true)
|
||||
else
|
||||
FrameStackTooltip_Toggle()
|
||||
end
|
||||
end
|
||||
|
||||
printNoTimestamp("|cffCC0000----------------------------|r")
|
||||
for i = 2, FrameStackTooltip:NumLines() do
|
||||
local text = _G["FrameStackTooltipTextLeft"..i]:GetText()
|
||||
if text and text ~= "" then
|
||||
printNoTimestamp(text)
|
||||
end
|
||||
end
|
||||
printNoTimestamp("|cffCC0000----------------------------|r")
|
||||
|
||||
updateCopyChat()
|
||||
|
||||
if not isPreviouslyShown then
|
||||
FrameStackTooltip_Toggle()
|
||||
end
|
||||
end
|
||||
|
||||
SLASH_TEXLIST1 = "/texlist"
|
||||
SlashCmdList.TEXLIST = function(frame)
|
||||
frame = getObject(frame)
|
||||
if not (frame and frame.GetNumRegions) then return end
|
||||
|
||||
for i = 1, frame:GetNumRegions() do
|
||||
local region = select(i, frame:GetRegions())
|
||||
if region.IsObjectType and region:IsObjectType("Texture") and region:GetTexture() then
|
||||
printNoTimestamp(region:GetTexture(), region:GetName(), region:GetDrawLayer())
|
||||
end
|
||||
end
|
||||
|
||||
updateCopyChat()
|
||||
end
|
||||
|
||||
SLASH_REGLIST1 = "/reglist"
|
||||
SlashCmdList.REGLIST = function(frame)
|
||||
frame = getObject(frame)
|
||||
if not (frame and frame.GetNumRegions) then return end
|
||||
|
||||
for i = 1, frame:GetNumRegions() do
|
||||
local region = select(i, frame:GetRegions())
|
||||
printNoTimestamp(i, region:GetObjectType(), region:GetName(), region:GetDrawLayer())
|
||||
end
|
||||
|
||||
updateCopyChat()
|
||||
end
|
||||
|
||||
SLASH_CHILDLIST1 = "/childlist"
|
||||
SlashCmdList.CHILDLIST = function(frame)
|
||||
frame = getObject(frame)
|
||||
if not (frame and frame.GetNumChildren) then return end
|
||||
|
||||
for i = 1, frame:GetNumChildren() do
|
||||
local obj = select(i, frame:GetChildren())
|
||||
printNoTimestamp(i, obj:GetObjectType(), obj:GetName(), obj:GetFrameStrata(), obj:GetFrameLevel())
|
||||
end
|
||||
|
||||
updateCopyChat()
|
||||
end
|
||||
|
||||
SLASH_GETPOINT1 = "/getpoint"
|
||||
SlashCmdList.GETPOINT = function(frame)
|
||||
frame = getObject(frame)
|
||||
if not frame then return end
|
||||
|
||||
local parent = frame:GetParent()
|
||||
local point, relativeTo, relativePoint, x, y, relativeName
|
||||
|
||||
for i = 1, frame:GetNumPoints() do
|
||||
point, relativeTo, relativePoint, x, y = frame:GetPoint(i)
|
||||
relativeName = relativeTo and relativeTo.GetName and (relativeTo:GetName() or tostring(relativeTo)) or "nil"
|
||||
|
||||
if point == relativePoint and relativeTo == parent then
|
||||
printNoTimestamp(format("\"%s\", %.0f, %.0f", point, x, y))
|
||||
else
|
||||
printNoTimestamp(format("\"%s\", %s, \"%s\", %.0f, %.0f", point, relativeName, relativePoint, x, y))
|
||||
end
|
||||
end
|
||||
|
||||
updateCopyChat()
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||
<Script file="ReloadUI.lua"/>
|
||||
<Script file="Frame.lua"/>
|
||||
<Script file="Test.lua"/>
|
||||
<Script file="Table.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,8 @@
|
||||
--Lua functions
|
||||
--WoW API / Variables
|
||||
local SlashCmdList = SlashCmdList
|
||||
-- GLOBALS: SLASH_RELOADUI1, SLASH_RELOADUI2
|
||||
|
||||
SLASH_RELOADUI1 = "/rl"
|
||||
SLASH_RELOADUI2 = "/reloadui"
|
||||
SlashCmdList.RELOADUI = ReloadUI
|
||||
@@ -0,0 +1,30 @@
|
||||
--Lua functions
|
||||
local pairs, type = pairs, type
|
||||
local setmetatable, getmetatable = setmetatable, getmetatable
|
||||
--WoW API / Variables
|
||||
|
||||
local function table_copy(t, deep, seen)
|
||||
if type(t) ~= "table" then return nil end
|
||||
|
||||
if not seen then
|
||||
seen = {}
|
||||
elseif seen[t] then
|
||||
return seen[t]
|
||||
end
|
||||
|
||||
local nt = {}
|
||||
for k, v in pairs(t) do
|
||||
if deep and type(v) == "table" then
|
||||
nt[k] = table_copy(v, deep, seen)
|
||||
else
|
||||
nt[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
setmetatable(nt, table_copy(getmetatable(t), deep, seen))
|
||||
seen[t] = nt
|
||||
|
||||
return nt
|
||||
end
|
||||
|
||||
table.copy = table_copy
|
||||
@@ -0,0 +1,5 @@
|
||||
--[[
|
||||
Going to leave this as my bullshit lua file.
|
||||
|
||||
So I can test stuff.
|
||||
]]
|
||||
@@ -0,0 +1,19 @@
|
||||
## Interface: 30300
|
||||
## Author: Elv, Bunny
|
||||
## Version: 6.10
|
||||
## Title: |cff1784d1E|r|cffe5e3e3lvUI|r
|
||||
## Notes: User Interface replacement AddOn for World of Warcraft.
|
||||
## SavedVariables: ElvDB, ElvPrivateDB
|
||||
## SavedVariablesPerCharacter: ElvCharacterDB
|
||||
## OptionalDeps: Blizzard_DebugTools, SharedMedia, Tukui, ButtonFacade
|
||||
## X-oUF: ElvUF
|
||||
|
||||
Developer\Load_Developer.xml
|
||||
Libraries\Load_Libraries.xml
|
||||
Init.lua
|
||||
Locales\Load_Locales.xml
|
||||
Media\Load_Media.xml
|
||||
Settings\Load_Config.xml
|
||||
Core\Load_Core.xml
|
||||
Layout\Load_Layout.xml
|
||||
Modules\Load_Modules.xml
|
||||
+426
@@ -0,0 +1,426 @@
|
||||
--[[
|
||||
~AddOn Engine~
|
||||
|
||||
To load the AddOn engine add this to the top of your file:
|
||||
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
]]
|
||||
|
||||
--Lua functions
|
||||
local _G, min, pairs, strsplit, unpack, wipe, type, tcopy = _G, min, pairs, strsplit, unpack, wipe, type, table.copy
|
||||
--WoW API / Variables
|
||||
local hooksecurefunc = hooksecurefunc
|
||||
local CreateFrame = CreateFrame
|
||||
local GetAddOnInfo = GetAddOnInfo
|
||||
local GetAddOnMetadata = GetAddOnMetadata
|
||||
local GetTime = GetTime
|
||||
local HideUIPanel = HideUIPanel
|
||||
local InCombatLockdown = InCombatLockdown
|
||||
local IsAddOnLoaded = IsAddOnLoaded
|
||||
local LoadAddOn = LoadAddOn
|
||||
local ReloadUI = ReloadUI
|
||||
|
||||
local ERR_NOT_IN_COMBAT = ERR_NOT_IN_COMBAT
|
||||
local GameMenuButtonLogout = GameMenuButtonLogout
|
||||
local GameMenuFrame = GameMenuFrame
|
||||
|
||||
BINDING_HEADER_ELVUI = GetAddOnMetadata(..., "Title")
|
||||
|
||||
local AceAddon, AceAddonMinor = LibStub("AceAddon-3.0")
|
||||
local CallbackHandler = LibStub("CallbackHandler-1.0")
|
||||
|
||||
local AddOnName, Engine = ...
|
||||
local AddOn = LibStub("AceAddon-3.0"):NewAddon(AddOnName, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0", "AceHook-3.0")
|
||||
AddOn.callbacks = AddOn.callbacks or CallbackHandler:New(AddOn)
|
||||
AddOn.DF = {profile = {}, global = {}}; AddOn.privateVars = {profile = {}} -- Defaults
|
||||
AddOn.Options = {type = "group", name = AddOnName, args = {}}
|
||||
|
||||
Engine[1] = AddOn
|
||||
Engine[2] = {}
|
||||
Engine[3] = AddOn.privateVars.profile
|
||||
Engine[4] = AddOn.DF.profile
|
||||
Engine[5] = AddOn.DF.global
|
||||
_G[AddOnName] = Engine
|
||||
|
||||
do
|
||||
AddOn.Libs = {}
|
||||
AddOn.LibsMinor = {}
|
||||
function AddOn:AddLib(name, major, minor)
|
||||
if not name then return end
|
||||
|
||||
-- in this case: `major` is the lib table and `minor` is the minor version
|
||||
if type(major) == "table" and type(minor) == "number" then
|
||||
self.Libs[name], self.LibsMinor[name] = major, minor
|
||||
else -- in this case: `major` is the lib name and `minor` is the silent switch
|
||||
self.Libs[name], self.LibsMinor[name] = LibStub(major, minor)
|
||||
end
|
||||
end
|
||||
|
||||
AddOn:AddLib("AceAddon", AceAddon, AceAddonMinor)
|
||||
AddOn:AddLib("AceDB", "AceDB-3.0")
|
||||
AddOn:AddLib("EP", "LibElvUIPlugin-1.0")
|
||||
AddOn:AddLib("LSM", "LibSharedMedia-3.0")
|
||||
AddOn:AddLib("ACL", "AceLocale-3.0-ElvUI")
|
||||
AddOn:AddLib("LAB", "LibActionButton-1.0-ElvUI")
|
||||
AddOn:AddLib("LAI", "LibAuraInfo-1.0-ElvUI", true)
|
||||
AddOn:AddLib("LBF", "LibButtonFacade", true)
|
||||
AddOn:AddLib("LDB", "LibDataBroker-1.1")
|
||||
AddOn:AddLib("DualSpec", "LibDualSpec-1.0")
|
||||
AddOn:AddLib("SimpleSticky", "LibSimpleSticky-1.0")
|
||||
AddOn:AddLib("SpellRange", "SpellRange-1.0")
|
||||
AddOn:AddLib("ItemSearch", "LibItemSearch-1.2-ElvUI")
|
||||
AddOn:AddLib("Compress", "LibCompress")
|
||||
AddOn:AddLib("Base64", "LibBase64-1.0-ElvUI")
|
||||
AddOn:AddLib("Translit", "LibTranslit-1.0")
|
||||
-- added on ElvUI_OptionsUI load: AceGUI, AceConfig, AceConfigDialog, AceConfigRegistry, AceDBOptions
|
||||
|
||||
-- backwards compatible for plugins
|
||||
AddOn.LSM = AddOn.Libs.LSM
|
||||
AddOn.Masque = AddOn.Libs.Masque
|
||||
end
|
||||
|
||||
AddOn.oUF = Engine.oUF
|
||||
AddOn.ActionBars = AddOn:NewModule("ActionBars","AceHook-3.0","AceEvent-3.0")
|
||||
AddOn.AFK = AddOn:NewModule("AFK","AceEvent-3.0","AceTimer-3.0")
|
||||
AddOn.Auras = AddOn:NewModule("Auras","AceHook-3.0","AceEvent-3.0")
|
||||
AddOn.Bags = AddOn:NewModule("Bags","AceHook-3.0","AceEvent-3.0","AceTimer-3.0")
|
||||
AddOn.Blizzard = AddOn:NewModule("Blizzard","AceEvent-3.0","AceHook-3.0")
|
||||
AddOn.Chat = AddOn:NewModule("Chat","AceTimer-3.0","AceHook-3.0","AceEvent-3.0")
|
||||
AddOn.DataBars = AddOn:NewModule("DataBars","AceEvent-3.0")
|
||||
AddOn.DataTexts = AddOn:NewModule("DataTexts","AceTimer-3.0","AceHook-3.0","AceEvent-3.0")
|
||||
AddOn.DebugTools = AddOn:NewModule("DebugTools","AceEvent-3.0","AceHook-3.0")
|
||||
AddOn.Distributor = AddOn:NewModule("Distributor","AceEvent-3.0","AceTimer-3.0","AceComm-3.0","AceSerializer-3.0")
|
||||
AddOn.Layout = AddOn:NewModule("Layout","AceEvent-3.0")
|
||||
AddOn.Minimap = AddOn:NewModule("Minimap","AceEvent-3.0")
|
||||
AddOn.Misc = AddOn:NewModule("Misc","AceEvent-3.0","AceTimer-3.0")
|
||||
AddOn.ModuleCopy = AddOn:NewModule("ModuleCopy","AceEvent-3.0","AceTimer-3.0","AceComm-3.0","AceSerializer-3.0")
|
||||
AddOn.NamePlates = AddOn:NewModule("NamePlates","AceHook-3.0","AceEvent-3.0","AceTimer-3.0")
|
||||
AddOn.PluginInstaller = AddOn:NewModule("PluginInstaller")
|
||||
AddOn.RaidUtility = AddOn:NewModule("RaidUtility","AceEvent-3.0")
|
||||
AddOn.ReminderBuffs = AddOn:NewModule("ReminderBuffs", "AceEvent-3.0")
|
||||
AddOn.Skins = AddOn:NewModule("Skins","AceTimer-3.0","AceHook-3.0","AceEvent-3.0")
|
||||
AddOn.Threat = AddOn:NewModule("Threat","AceEvent-3.0")
|
||||
AddOn.Tooltip = AddOn:NewModule("Tooltip","AceTimer-3.0","AceHook-3.0","AceEvent-3.0")
|
||||
AddOn.TotemBar = AddOn:NewModule("Totems","AceEvent-3.0")
|
||||
AddOn.UnitFrames = AddOn:NewModule("UnitFrames","AceTimer-3.0","AceEvent-3.0","AceHook-3.0")
|
||||
AddOn.WorldMap = AddOn:NewModule("WorldMap","AceHook-3.0","AceEvent-3.0","AceTimer-3.0")
|
||||
|
||||
do
|
||||
local arg2, arg3 = "([%(%)%.%%%+%-%*%?%[%^%$])", "%%%1"
|
||||
function AddOn:EscapeString(str)
|
||||
return gsub(str, arg2, arg3)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
DisableAddOn("ElvUI_EverySecondCounts")
|
||||
DisableAddOn("ElvUI_FogOfWar")
|
||||
DisableAddOn("ElvUI_VisualAuraTimers")
|
||||
DisableAddOn("ElvUI_MinimapButtons")
|
||||
DisableAddOn("ElvUI_ChannelAlerts")
|
||||
end
|
||||
|
||||
function AddOn:OnInitialize()
|
||||
if not ElvCharacterDB then
|
||||
ElvCharacterDB = {}
|
||||
end
|
||||
|
||||
self.db = tcopy(self.DF.profile, true)
|
||||
self.global = tcopy(self.DF.global, true)
|
||||
|
||||
if ElvDB then
|
||||
if ElvDB.global then
|
||||
self:CopyTable(self.global, ElvDB.global)
|
||||
end
|
||||
|
||||
local profileKey
|
||||
if ElvDB.profileKeys then
|
||||
profileKey = ElvDB.profileKeys[self.myname.." - "..self.myrealm]
|
||||
end
|
||||
|
||||
if profileKey and ElvDB.profiles and ElvDB.profiles[profileKey] then
|
||||
self:CopyTable(self.db, ElvDB.profiles[profileKey])
|
||||
end
|
||||
end
|
||||
|
||||
self.private = tcopy(self.privateVars.profile, true)
|
||||
|
||||
if ElvPrivateDB then
|
||||
local profileKey
|
||||
if ElvPrivateDB.profileKeys then
|
||||
profileKey = ElvPrivateDB.profileKeys[self.myname.." - "..self.myrealm]
|
||||
end
|
||||
|
||||
if profileKey and ElvPrivateDB.profiles and ElvPrivateDB.profiles[profileKey] then
|
||||
self:CopyTable(self.private, ElvPrivateDB.profiles[profileKey])
|
||||
end
|
||||
end
|
||||
|
||||
self.twoPixelsPlease = false
|
||||
self.ScanTooltip = CreateFrame("GameTooltip", "ElvUI_ScanTooltip", _G.UIParent, "GameTooltipTemplate")
|
||||
self.PixelMode = self.twoPixelsPlease or self.private.general.pixelPerfect -- keep this over `UIScale`
|
||||
self:UIScale(true)
|
||||
self:UpdateMedia()
|
||||
|
||||
self:RegisterEvent("UPDATE_FLOATING_CHAT_WINDOWS", "PixelScaleChanged")
|
||||
self:RegisterEvent("PLAYER_REGEN_DISABLED")
|
||||
self:Contruct_StaticPopups()
|
||||
self:InitializeInitialModules()
|
||||
|
||||
if IsAddOnLoaded("Tukui") then
|
||||
self:StaticPopup_Show("TUKUI_ELVUI_INCOMPATIBLE")
|
||||
end
|
||||
|
||||
local GameMenuButton = CreateFrame("Button", "ElvUI_MenuButton", GameMenuFrame, "GameMenuButtonTemplate")
|
||||
GameMenuButton:SetText(self.title)
|
||||
GameMenuButton:SetScript("OnClick", function()
|
||||
AddOn:ToggleOptionsUI()
|
||||
HideUIPanel(GameMenuFrame)
|
||||
end)
|
||||
GameMenuFrame[AddOnName] = GameMenuButton
|
||||
|
||||
GameMenuButton:Size(GameMenuButtonLogout:GetWidth(), GameMenuButtonLogout:GetHeight())
|
||||
GameMenuButtonRatings:HookScript("OnShow", function(self)
|
||||
GameMenuFrame:SetHeight(GameMenuFrame:GetHeight() + self:GetHeight())
|
||||
end)
|
||||
GameMenuButtonRatings:HookScript("OnHide", function(self)
|
||||
GameMenuFrame:SetHeight(GameMenuFrame:GetHeight() - self:GetHeight())
|
||||
end)
|
||||
|
||||
GameMenuFrame:HookScript("OnShow", function()
|
||||
if not GameMenuFrame.isElvUI then
|
||||
GameMenuFrame:SetHeight(GameMenuFrame:GetHeight() + GameMenuButtonLogout:GetHeight() + 1)
|
||||
GameMenuFrame.isElvUI = true
|
||||
end
|
||||
local _, relTo = GameMenuButtonLogout:GetPoint()
|
||||
if relTo ~= GameMenuFrame[AddOnName] then
|
||||
GameMenuFrame[AddOnName]:ClearAllPoints()
|
||||
GameMenuFrame[AddOnName]:Point("TOPLEFT", relTo, "BOTTOMLEFT", 0, -1)
|
||||
GameMenuButtonLogout:ClearAllPoints()
|
||||
GameMenuButtonLogout:Point("TOPLEFT", GameMenuFrame[AddOnName], "BOTTOMLEFT", 0, -16)
|
||||
end
|
||||
end)
|
||||
|
||||
self.loadedtime = GetTime()
|
||||
end
|
||||
|
||||
local LoadUI = CreateFrame("Frame")
|
||||
LoadUI:RegisterEvent("PLAYER_LOGIN")
|
||||
LoadUI:SetScript("OnEvent", function()
|
||||
AddOn:Initialize()
|
||||
end)
|
||||
|
||||
function AddOn:PLAYER_REGEN_ENABLED()
|
||||
self:ToggleOptionsUI()
|
||||
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
|
||||
end
|
||||
|
||||
function AddOn:PLAYER_REGEN_DISABLED()
|
||||
local err
|
||||
|
||||
if IsAddOnLoaded("ElvUI_OptionsUI") then
|
||||
local ACD = self.Libs.AceConfigDialog
|
||||
if ACD and ACD.OpenFrames and ACD.OpenFrames[AddOnName] then
|
||||
self:RegisterEvent("PLAYER_REGEN_ENABLED")
|
||||
ACD:Close(AddOnName)
|
||||
err = true
|
||||
end
|
||||
end
|
||||
|
||||
if self.CreatedMovers then
|
||||
for name in pairs(self.CreatedMovers) do
|
||||
local mover = _G[name]
|
||||
if mover and mover:IsShown() then
|
||||
mover:Hide()
|
||||
err = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if err then
|
||||
self:Print(ERR_NOT_IN_COMBAT)
|
||||
end
|
||||
end
|
||||
|
||||
function AddOn:ResetProfile()
|
||||
local profileKey
|
||||
|
||||
if ElvPrivateDB.profileKeys then
|
||||
profileKey = ElvPrivateDB.profileKeys[self.myname.." - "..self.myrealm]
|
||||
|
||||
if profileKey and ElvPrivateDB.profiles and ElvPrivateDB.profiles[profileKey] then
|
||||
ElvPrivateDB.profiles[profileKey] = nil
|
||||
end
|
||||
end
|
||||
|
||||
ElvCharacterDB = nil
|
||||
self.data:_ResetProfile()
|
||||
ReloadUI()
|
||||
end
|
||||
|
||||
function AddOn:OnProfileReset()
|
||||
AddOn:StaticPopup_Show("RESET_PROFILE_PROMPT")
|
||||
end
|
||||
|
||||
function AddOn:ResetConfigSettings()
|
||||
AddOn.configSavedPositionTop, AddOn.configSavedPositionLeft = nil, nil
|
||||
AddOn.global.general.AceGUI = AddOn:CopyTable({}, AddOn.DF.global.general.AceGUI)
|
||||
end
|
||||
|
||||
function AddOn:GetConfigPosition()
|
||||
return AddOn.configSavedPositionTop, AddOn.configSavedPositionLeft
|
||||
end
|
||||
|
||||
function AddOn:GetConfigSize()
|
||||
return AddOn.global.general.AceGUI.width, AddOn.global.general.AceGUI.height
|
||||
end
|
||||
|
||||
function AddOn:UpdateConfigSize(reset)
|
||||
local frame = self.GUIFrame
|
||||
if not frame then return end
|
||||
|
||||
local maxWidth, maxHeight = self.UIParent:GetSize()
|
||||
frame:SetMinResize(600, 500)
|
||||
frame:SetMaxResize(maxWidth-50, maxHeight-50)
|
||||
|
||||
self.Libs.AceConfigDialog:SetDefaultSize(AddOnName, self:GetConfigDefaultSize())
|
||||
|
||||
local status = frame.obj and frame.obj.status
|
||||
if status then
|
||||
if reset then
|
||||
self:ResetConfigSettings()
|
||||
|
||||
status.top, status.left = self:GetConfigPosition()
|
||||
status.width, status.height = self:GetConfigDefaultSize()
|
||||
|
||||
frame.obj:ApplyStatus()
|
||||
else
|
||||
local top, left = self:GetConfigPosition()
|
||||
if top and left then
|
||||
status.top, status.left = top, left
|
||||
|
||||
frame.obj:ApplyStatus()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AddOn:GetConfigDefaultSize()
|
||||
local width, height = AddOn:GetConfigSize()
|
||||
local maxWidth, maxHeight = AddOn.UIParent:GetSize()
|
||||
width, height = min(maxWidth - 50, width), min(maxHeight - 50, height)
|
||||
return width, height
|
||||
end
|
||||
|
||||
function AddOn:ConfigStopMovingOrSizing()
|
||||
if self.obj and self.obj.status then
|
||||
AddOn.configSavedPositionTop, AddOn.configSavedPositionLeft = AddOn:Round(self:GetTop(), 2), AddOn:Round(self:GetLeft(), 2)
|
||||
AddOn.global.general.AceGUI.width, AddOn.global.general.AceGUI.height = AddOn:Round(self:GetWidth(), 2), AddOn:Round(self:GetHeight(), 2)
|
||||
end
|
||||
end
|
||||
|
||||
local pageNodes = {}
|
||||
function AddOn:ToggleOptionsUI(msg)
|
||||
if InCombatLockdown() then
|
||||
self:Print(ERR_NOT_IN_COMBAT)
|
||||
self:RegisterEvent("PLAYER_REGEN_ENABLED")
|
||||
return
|
||||
end
|
||||
|
||||
if not IsAddOnLoaded("ElvUI_OptionsUI") then
|
||||
local noConfig
|
||||
local _, _, _, _, reason = GetAddOnInfo("ElvUI_OptionsUI")
|
||||
if reason ~= "MISSING" and reason ~= "DISABLED" then
|
||||
self.GUIFrame = false
|
||||
LoadAddOn("ElvUI_OptionsUI")
|
||||
|
||||
--For some reason, GetAddOnInfo reason is "DEMAND_LOADED" even if the addon is disabled.
|
||||
--Workaround: Try to load addon and check if it is loaded right after.
|
||||
if not IsAddOnLoaded("ElvUI_OptionsUI") then noConfig = true end
|
||||
|
||||
-- version check elvui options if it's actually enabled
|
||||
if (not noConfig) and GetAddOnMetadata("ElvUI_OptionsUI", "Version") ~= "1.06" then
|
||||
self:StaticPopup_Show("CLIENT_UPDATE_REQUEST")
|
||||
end
|
||||
else
|
||||
noConfig = true
|
||||
end
|
||||
|
||||
if noConfig then
|
||||
self:Print("|cffff0000Error -- Addon 'ElvUI_OptionsUI' not found or is disabled.|r")
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local ACD = self.Libs.AceConfigDialog
|
||||
local ConfigOpen = ACD and ACD.OpenFrames and ACD.OpenFrames[AddOnName]
|
||||
|
||||
local pages, msgStr
|
||||
if msg and msg ~= "" then
|
||||
pages = {strsplit(",", msg)}
|
||||
msgStr = gsub(msg, ",","\001")
|
||||
end
|
||||
|
||||
local mode = "Close"
|
||||
if not ConfigOpen or (pages ~= nil) then
|
||||
if pages ~= nil then
|
||||
local pageCount, index, mainSel = #pages
|
||||
if pageCount > 1 then
|
||||
wipe(pageNodes)
|
||||
index = 0
|
||||
|
||||
local main, mainNode, mainSelStr, sub, subNode, subSel
|
||||
for i = 1, pageCount do
|
||||
if i == 1 then
|
||||
main = pages[i] and ACD and ACD.Status and ACD.Status.ElvUI
|
||||
mainSel = main and main.status and main.status.groups and main.status.groups.selected
|
||||
mainSelStr = mainSel and ("^"..self:EscapeString(mainSel).."\001")
|
||||
mainNode = main and main.children and main.children[pages[i]]
|
||||
pageNodes[index + 1], pageNodes[index + 2] = main, mainNode
|
||||
else
|
||||
sub = pages[i] and pageNodes[i] and ((i == pageCount and pageNodes[i]) or pageNodes[i].children[pages[i]])
|
||||
subSel = sub and sub.status and sub.status.groups and sub.status.groups.selected
|
||||
subNode = (mainSelStr and msgStr:match(mainSelStr..self:EscapeString(pages[i]).."$") and (subSel and subSel == pages[i])) or ((i == pageCount and not subSel) and mainSel and mainSel == msgStr)
|
||||
pageNodes[index + 1], pageNodes[index + 2] = sub, subNode
|
||||
end
|
||||
index = index + 2
|
||||
end
|
||||
else
|
||||
local main = pages[1] and ACD and ACD.Status and ACD.Status.ElvUI
|
||||
mainSel = main and main.status and main.status.groups and main.status.groups.selected
|
||||
end
|
||||
|
||||
if ConfigOpen and ((not index and mainSel and mainSel == msg) or (index and pageNodes and pageNodes[index])) then
|
||||
mode = "Close"
|
||||
else
|
||||
mode = "Open"
|
||||
end
|
||||
else
|
||||
mode = "Open"
|
||||
end
|
||||
end
|
||||
|
||||
if ACD then
|
||||
ACD[mode](ACD, AddOnName)
|
||||
end
|
||||
|
||||
if mode == "Open" then
|
||||
ConfigOpen = ACD and ACD.OpenFrames and ACD.OpenFrames[AddOnName]
|
||||
if ConfigOpen then
|
||||
local frame = ConfigOpen.frame
|
||||
if frame and not self.GUIFrame then
|
||||
self.GUIFrame = frame
|
||||
ElvUIGUIFrame = self.GUIFrame
|
||||
|
||||
self:UpdateConfigSize()
|
||||
hooksecurefunc(frame, "StopMovingOrSizing", AddOn.ConfigStopMovingOrSizing)
|
||||
end
|
||||
end
|
||||
|
||||
if ACD and pages then
|
||||
ACD:SelectGroup(AddOnName, unpack(pages))
|
||||
end
|
||||
end
|
||||
|
||||
GameTooltip:Hide() --Just in case you're mouseovered something and it closes.
|
||||
end
|
||||
@@ -0,0 +1,521 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local LO = E:GetModule("Layout")
|
||||
local DT = E:GetModule("DataTexts")
|
||||
|
||||
--Lua functions
|
||||
--WoW API / Variables
|
||||
local CreateFrame = CreateFrame
|
||||
local UIFrameFadeIn, UIFrameFadeOut = UIFrameFadeIn, UIFrameFadeOut
|
||||
|
||||
local PANEL_HEIGHT = 22
|
||||
local SIDE_BUTTON_WIDTH = 16
|
||||
|
||||
local function Panel_OnShow(self)
|
||||
self:SetFrameLevel(0)
|
||||
self:SetFrameStrata("BACKGROUND")
|
||||
end
|
||||
|
||||
function LO:Initialize()
|
||||
self.Initialized = true
|
||||
self:CreateChatPanels()
|
||||
self:CreateMinimapPanels()
|
||||
self:SetDataPanelStyle()
|
||||
|
||||
self.BottomPanel = CreateFrame("Frame", "ElvUI_BottomPanel", E.UIParent)
|
||||
self.BottomPanel:SetTemplate("Transparent")
|
||||
self.BottomPanel:Point("BOTTOMLEFT", E.UIParent, "BOTTOMLEFT", -1, -1)
|
||||
self.BottomPanel:Point("BOTTOMRIGHT", E.UIParent, "BOTTOMRIGHT", 1, -1)
|
||||
self.BottomPanel:Height(PANEL_HEIGHT)
|
||||
self.BottomPanel:SetScript("OnShow", Panel_OnShow)
|
||||
Panel_OnShow(self.BottomPanel)
|
||||
self:BottomPanelVisibility()
|
||||
|
||||
self.TopPanel = CreateFrame("Frame", "ElvUI_TopPanel", E.UIParent)
|
||||
self.TopPanel:SetTemplate("Transparent")
|
||||
self.TopPanel:Point("TOPLEFT", E.UIParent, "TOPLEFT", -1, 1)
|
||||
self.TopPanel:Point("TOPRIGHT", E.UIParent, "TOPRIGHT", 1, 1)
|
||||
self.TopPanel:Height(PANEL_HEIGHT)
|
||||
self.TopPanel:SetScript("OnShow", Panel_OnShow)
|
||||
Panel_OnShow(self.TopPanel)
|
||||
self:TopPanelVisibility()
|
||||
end
|
||||
|
||||
function LO:BottomPanelVisibility()
|
||||
if E.db.general.bottomPanel then
|
||||
self.BottomPanel:Show()
|
||||
else
|
||||
self.BottomPanel:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
function LO:TopPanelVisibility()
|
||||
if E.db.general.topPanel then
|
||||
self.TopPanel:Show()
|
||||
else
|
||||
self.TopPanel:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
local function ChatPanelLeft_OnFade()
|
||||
LeftChatPanel:Hide()
|
||||
end
|
||||
|
||||
local function ChatPanelRight_OnFade()
|
||||
RightChatPanel:Hide()
|
||||
end
|
||||
|
||||
local function ChatButton_OnEnter(self)
|
||||
if E.db[self.parent:GetName().."Faded"] then
|
||||
self.parent:Show()
|
||||
UIFrameFadeIn(self.parent, 0.2, self.parent:GetAlpha(), 1)
|
||||
if E.db.chat.fadeChatToggles then
|
||||
UIFrameFadeIn(self, 0.2, self:GetAlpha(), 1)
|
||||
end
|
||||
end
|
||||
|
||||
if self == LeftChatToggleButton then
|
||||
GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT", 0, (E.PixelMode and 1 or 3))
|
||||
GameTooltip:ClearLines()
|
||||
GameTooltip:AddDoubleLine(L["Left Click:"], L["Toggle Chat Frame"], 1, 1, 1)
|
||||
else
|
||||
GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT", 0, (E.PixelMode and 1 or 3))
|
||||
GameTooltip:ClearLines()
|
||||
GameTooltip:AddDoubleLine(L["Left Click:"], L["Toggle Chat Frame"], 1, 1, 1)
|
||||
end
|
||||
|
||||
GameTooltip:Show()
|
||||
end
|
||||
|
||||
local function ChatButton_OnLeave(self)
|
||||
if E.db[self.parent:GetName().."Faded"] then
|
||||
UIFrameFadeOut(self.parent, 0.2, self.parent:GetAlpha(), 0)
|
||||
self.parent.fadeInfo.finishedFunc = self.parent.fadeFunc
|
||||
|
||||
if E.db.chat.fadeChatToggles then
|
||||
UIFrameFadeOut(self, 0.2, self:GetAlpha(), 0)
|
||||
end
|
||||
end
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
local function ChatButton_OnClick(self)
|
||||
GameTooltip:Hide()
|
||||
|
||||
local name = self.parent:GetName().."Faded"
|
||||
if E.db[name] then
|
||||
E.db[name] = nil
|
||||
UIFrameFadeIn(self.parent, 0.2, self.parent:GetAlpha(), 1)
|
||||
if E.db.chat.fadeChatToggles then
|
||||
UIFrameFadeIn(self, 0.2, self:GetAlpha(), 1)
|
||||
end
|
||||
else
|
||||
E.db[name] = true
|
||||
UIFrameFadeOut(self.parent, 0.2, self.parent:GetAlpha(), 0)
|
||||
self.parent.fadeInfo.finishedFunc = self.parent.fadeFunc
|
||||
if E.db.chat.fadeChatToggles then
|
||||
UIFrameFadeOut(self, 0.2, self:GetAlpha(), 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function HideLeftChat()
|
||||
ChatButton_OnClick(LeftChatToggleButton)
|
||||
end
|
||||
|
||||
function HideRightChat()
|
||||
ChatButton_OnClick(RightChatToggleButton)
|
||||
end
|
||||
|
||||
function HideBothChat()
|
||||
ChatButton_OnClick(LeftChatToggleButton)
|
||||
ChatButton_OnClick(RightChatToggleButton)
|
||||
end
|
||||
|
||||
function LO:ToggleChatTabPanels(rightOverride, leftOverride)
|
||||
if leftOverride or not E.db.chat.panelTabBackdrop then
|
||||
LeftChatTab:Hide()
|
||||
else
|
||||
LeftChatTab:Show()
|
||||
end
|
||||
|
||||
if rightOverride or not E.db.chat.panelTabBackdrop then
|
||||
RightChatTab:Hide()
|
||||
else
|
||||
RightChatTab:Show()
|
||||
end
|
||||
end
|
||||
|
||||
function LO:SetChatTabStyle()
|
||||
local tabStyle = E.db.chat.panelTabTransparency and "Transparent" or nil
|
||||
local glossTex = not tabStyle and true or nil
|
||||
|
||||
LeftChatTab:SetTemplate(tabStyle, glossTex)
|
||||
RightChatTab:SetTemplate(tabStyle, glossTex)
|
||||
end
|
||||
|
||||
function LO:SetDataPanelStyle()
|
||||
local miniStyle = E.db.datatexts.panelTransparency and "Transparent" or "Default"
|
||||
local panelStyle = (not E.db.datatexts.panelBackdrop) and "NoBackdrop" or miniStyle
|
||||
|
||||
local panelGlossTex = (panelStyle and true) or nil
|
||||
local miniGlossTex = (miniStyle and nil) or true
|
||||
|
||||
LeftChatDataPanel:SetTemplate(panelStyle, panelGlossTex)
|
||||
LeftChatToggleButton:SetTemplate(panelStyle, panelGlossTex)
|
||||
RightChatDataPanel:SetTemplate(panelStyle, panelGlossTex)
|
||||
RightChatToggleButton:SetTemplate(panelStyle, panelGlossTex)
|
||||
|
||||
LeftMiniPanel:SetTemplate(miniStyle, miniGlossTex)
|
||||
RightMiniPanel:SetTemplate(miniStyle, miniGlossTex)
|
||||
ElvConfigToggle:SetTemplate(miniStyle, miniGlossTex)
|
||||
end
|
||||
|
||||
function LO:RepositionChatDataPanels()
|
||||
LeftChatDataPanel:ClearAllPoints()
|
||||
RightChatDataPanel:ClearAllPoints()
|
||||
|
||||
local SPACING = E.Border*3 - E.Spacing
|
||||
local SIDE_BUTTON_SPACING = (E.PixelMode and E.Border*4) or SPACING*2
|
||||
|
||||
--Left Chat Tab
|
||||
LeftChatTab:Point("TOPLEFT", LeftChatPanel, "TOPLEFT", SPACING, -SPACING)
|
||||
LeftChatTab:Point("TOPRIGHT", LeftChatPanel, "TOPRIGHT", -SPACING, -SPACING)
|
||||
LeftChatTab:Point("BOTTOMRIGHT", LeftChatPanel, "TOPRIGHT", -SPACING, -(SPACING + PANEL_HEIGHT))
|
||||
LeftChatTab:Point("BOTTOMLEFT", LeftChatPanel, "TOPLEFT", SPACING, -(SPACING + PANEL_HEIGHT))
|
||||
|
||||
--Left Chat Data Panel
|
||||
LeftChatDataPanel:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT", SPACING + SIDE_BUTTON_WIDTH, SPACING)
|
||||
LeftChatDataPanel:Point("BOTTOMRIGHT", LeftChatPanel, "BOTTOMRIGHT", -SPACING, SPACING)
|
||||
LeftChatDataPanel:Point("TOPRIGHT", LeftChatPanel, "BOTTOMRIGHT", -SPACING, (SPACING + PANEL_HEIGHT))
|
||||
LeftChatDataPanel:Point("TOPLEFT", LeftChatPanel, "BOTTOMLEFT", SIDE_BUTTON_SPACING + SIDE_BUTTON_WIDTH, (SPACING + PANEL_HEIGHT))
|
||||
|
||||
--Left Chat Toggle Button
|
||||
LeftChatToggleButton:Point("TOPRIGHT", LeftChatDataPanel, "TOPLEFT", E.Border - E.Spacing*3, 0)
|
||||
LeftChatToggleButton:Point("TOPLEFT", LeftChatDataPanel, "TOPLEFT", -E.Border - E.Spacing*3 - SIDE_BUTTON_WIDTH, 0)
|
||||
LeftChatToggleButton:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT", SPACING, SPACING)
|
||||
LeftChatToggleButton:Point("BOTTOMRIGHT", LeftChatPanel, "BOTTOMLEFT", SPACING + SIDE_BUTTON_WIDTH, SPACING)
|
||||
|
||||
--Right Chat Tab
|
||||
RightChatTab:Point("TOPRIGHT", RightChatPanel, "TOPRIGHT", -SPACING, -SPACING)
|
||||
RightChatTab:Point("TOPLEFT", RightChatPanel, "TOPLEFT", SPACING, -SPACING)
|
||||
RightChatTab:Point("BOTTOMLEFT", RightChatPanel, "TOPLEFT", SPACING, -(SPACING + PANEL_HEIGHT))
|
||||
RightChatTab:Point("BOTTOMRIGHT", RightChatPanel, "TOPRIGHT", -SPACING, -(SPACING + PANEL_HEIGHT))
|
||||
|
||||
--Right Chat Data Panel
|
||||
RightChatDataPanel:Point("BOTTOMLEFT", RightChatPanel, "BOTTOMLEFT", SPACING, SPACING)
|
||||
RightChatDataPanel:Point("BOTTOMRIGHT", RightChatPanel, "BOTTOMRIGHT", -SPACING-SIDE_BUTTON_WIDTH, SPACING)
|
||||
RightChatDataPanel:Point("TOPRIGHT", RightChatPanel, "BOTTOMRIGHT", -(SIDE_BUTTON_SPACING + SIDE_BUTTON_WIDTH), SPACING + PANEL_HEIGHT)
|
||||
RightChatDataPanel:Point("TOPLEFT", RightChatPanel, "BOTTOMLEFT", (SPACING), SPACING + PANEL_HEIGHT)
|
||||
|
||||
--Right Chat Toggle Button
|
||||
RightChatToggleButton:Point("TOPLEFT", RightChatDataPanel, "TOPRIGHT", -E.Border + E.Spacing*3, 0)
|
||||
RightChatToggleButton:Point("TOPRIGHT", RightChatDataPanel, "TOPRIGHT", E.Border + E.Spacing*3 + SIDE_BUTTON_WIDTH, 0)
|
||||
RightChatToggleButton:Point("BOTTOMRIGHT", RightChatPanel, "BOTTOMRIGHT", -SPACING, SPACING)
|
||||
RightChatToggleButton:Point("BOTTOMLEFT", RightChatPanel, "BOTTOMRIGHT", -SPACING - SIDE_BUTTON_WIDTH, SPACING)
|
||||
end
|
||||
|
||||
function LO:ToggleChatPanels()
|
||||
LeftChatDataPanel:ClearAllPoints()
|
||||
RightChatDataPanel:ClearAllPoints()
|
||||
|
||||
local SPACING = E.Border*3 - E.Spacing
|
||||
local SIDE_BUTTON_SPACING = (E.PixelMode and E.Border*4) or SPACING*2
|
||||
|
||||
if E.db.datatexts.leftChatPanel then
|
||||
LeftChatDataPanel:Show()
|
||||
LeftChatToggleButton:Show()
|
||||
else
|
||||
LeftChatDataPanel:Hide()
|
||||
LeftChatToggleButton:Hide()
|
||||
end
|
||||
|
||||
if E.db.datatexts.rightChatPanel then
|
||||
RightChatDataPanel:Show()
|
||||
RightChatToggleButton:Show()
|
||||
else
|
||||
RightChatDataPanel:Hide()
|
||||
RightChatToggleButton:Hide()
|
||||
end
|
||||
|
||||
local panelBackdrop = E.db.chat.panelBackdrop
|
||||
if panelBackdrop == "SHOWBOTH" then
|
||||
LeftChatPanel.backdrop:Show()
|
||||
RightChatPanel.backdrop:Show()
|
||||
LeftChatDataPanel:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT", SIDE_BUTTON_SPACING + SIDE_BUTTON_WIDTH, SPACING)
|
||||
LeftChatDataPanel:Point("TOPRIGHT", LeftChatPanel, "BOTTOMRIGHT", -SPACING, (SPACING + PANEL_HEIGHT))
|
||||
RightChatDataPanel:Point("BOTTOMLEFT", RightChatPanel, "BOTTOMLEFT", SPACING, SPACING)
|
||||
RightChatDataPanel:Point("TOPRIGHT", RightChatPanel, "BOTTOMRIGHT", -(SIDE_BUTTON_SPACING + SIDE_BUTTON_WIDTH), SPACING + PANEL_HEIGHT)
|
||||
LeftChatToggleButton:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT", SPACING, SPACING)
|
||||
RightChatToggleButton:Point("BOTTOMRIGHT", RightChatPanel, "BOTTOMRIGHT", -SPACING, SPACING)
|
||||
LO:ToggleChatTabPanels()
|
||||
elseif panelBackdrop == "HIDEBOTH" then
|
||||
LeftChatPanel.backdrop:Hide()
|
||||
RightChatPanel.backdrop:Hide()
|
||||
LeftChatDataPanel:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT", SIDE_BUTTON_WIDTH, 0)
|
||||
LeftChatDataPanel:Point("TOPRIGHT", LeftChatPanel, "BOTTOMRIGHT", 0, PANEL_HEIGHT)
|
||||
RightChatDataPanel:Point("BOTTOMLEFT", RightChatPanel, "BOTTOMLEFT")
|
||||
RightChatDataPanel:Point("TOPRIGHT", RightChatPanel, "BOTTOMRIGHT", -SIDE_BUTTON_WIDTH, PANEL_HEIGHT)
|
||||
LeftChatToggleButton:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT")
|
||||
RightChatToggleButton:Point("BOTTOMRIGHT", RightChatPanel, "BOTTOMRIGHT")
|
||||
LO:ToggleChatTabPanels(true, true)
|
||||
elseif panelBackdrop == "LEFT" then
|
||||
LeftChatPanel.backdrop:Show()
|
||||
RightChatPanel.backdrop:Hide()
|
||||
LeftChatDataPanel:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT", SIDE_BUTTON_SPACING + SIDE_BUTTON_WIDTH, SPACING)
|
||||
LeftChatDataPanel:Point("TOPRIGHT", LeftChatPanel, "BOTTOMRIGHT", -SPACING, (SPACING + PANEL_HEIGHT))
|
||||
RightChatDataPanel:Point("BOTTOMLEFT", RightChatPanel, "BOTTOMLEFT")
|
||||
RightChatDataPanel:Point("TOPRIGHT", RightChatPanel, "BOTTOMRIGHT", -SIDE_BUTTON_WIDTH, PANEL_HEIGHT)
|
||||
LeftChatToggleButton:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT", SPACING, SPACING)
|
||||
RightChatToggleButton:Point("BOTTOMRIGHT", RightChatPanel, "BOTTOMRIGHT")
|
||||
LO:ToggleChatTabPanels(true)
|
||||
else
|
||||
LeftChatPanel.backdrop:Hide()
|
||||
RightChatPanel.backdrop:Show()
|
||||
LeftChatDataPanel:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT", SIDE_BUTTON_WIDTH, 0)
|
||||
LeftChatDataPanel:Point("TOPRIGHT", LeftChatPanel, "BOTTOMRIGHT", 0, PANEL_HEIGHT)
|
||||
RightChatDataPanel:Point("BOTTOMLEFT", RightChatPanel, "BOTTOMLEFT", SPACING, SPACING)
|
||||
RightChatDataPanel:Point("TOPRIGHT", RightChatPanel, "BOTTOMRIGHT", -(SIDE_BUTTON_SPACING + SIDE_BUTTON_WIDTH), SPACING + PANEL_HEIGHT)
|
||||
LeftChatToggleButton:Point("BOTTOMLEFT", LeftChatPanel, "BOTTOMLEFT")
|
||||
RightChatToggleButton:Point("BOTTOMRIGHT", RightChatPanel, "BOTTOMRIGHT", -SPACING, SPACING)
|
||||
LO:ToggleChatTabPanels(nil, true)
|
||||
end
|
||||
end
|
||||
|
||||
function LO:CreateChatPanels()
|
||||
local SPACING = E.Border*3 - E.Spacing
|
||||
local SIDE_BUTTON_SPACING = (E.PixelMode and E.Border*4) or SPACING*2
|
||||
|
||||
--Left Chat
|
||||
local lchat = CreateFrame("Frame", "LeftChatPanel", E.UIParent)
|
||||
lchat:SetFrameStrata("BACKGROUND")
|
||||
lchat:SetFrameLevel(100)
|
||||
lchat:Size(E.db.chat.panelWidth, E.db.chat.panelHeight)
|
||||
lchat:Point("BOTTOMLEFT", E.UIParent, 4, 4)
|
||||
lchat:CreateBackdrop("Transparent")
|
||||
lchat.backdrop.ignoreBackdropColors = true
|
||||
lchat.backdrop:SetAllPoints()
|
||||
E:CreateMover(lchat, "LeftChatMover", L["Left Chat"], nil, nil, nil, nil, nil, "chat,general")
|
||||
|
||||
--Background Texture
|
||||
lchat.tex = lchat:CreateTexture(nil, "OVERLAY")
|
||||
lchat.tex:SetInside()
|
||||
lchat.tex:SetTexture(E.db.chat.panelBackdropNameLeft)
|
||||
lchat.tex:SetAlpha(E.db.general.backdropfadecolor.a - 0.7 > 0 and E.db.general.backdropfadecolor.a - 0.7 or 0.5)
|
||||
|
||||
--Left Chat Tab
|
||||
local lchattab = CreateFrame("Frame", "LeftChatTab", lchat)
|
||||
lchattab:Point("TOPLEFT", lchat, "TOPLEFT", SPACING, -SPACING)
|
||||
lchattab:Point("TOPRIGHT", lchat, "TOPRIGHT", -SPACING, -SPACING)
|
||||
lchattab:Point("BOTTOMRIGHT", lchat, "TOPRIGHT", -SPACING, -(SPACING + PANEL_HEIGHT))
|
||||
lchattab:Point("BOTTOMLEFT", lchat, "TOPLEFT", SPACING, -(SPACING + PANEL_HEIGHT))
|
||||
lchattab:SetTemplate(E.db.chat.panelTabTransparency and "Transparent" or "Default", true)
|
||||
|
||||
--Left Chat Data Panel
|
||||
local lchatdp = CreateFrame("Frame", "LeftChatDataPanel", lchat)
|
||||
lchatdp:Point("BOTTOMLEFT", lchat, "BOTTOMLEFT", SPACING + SIDE_BUTTON_WIDTH, SPACING)
|
||||
lchatdp:Point("BOTTOMRIGHT", lchat, "BOTTOMRIGHT", -SPACING, SPACING)
|
||||
lchatdp:Point("TOPRIGHT", lchat, "BOTTOMRIGHT", -SPACING, (SPACING + PANEL_HEIGHT))
|
||||
lchatdp:Point("TOPLEFT", lchat, "BOTTOMLEFT", SIDE_BUTTON_SPACING+SIDE_BUTTON_WIDTH, (SPACING + PANEL_HEIGHT))
|
||||
lchatdp:SetTemplate(E.db.datatexts.panelTransparency and "Transparent" or "Default", true)
|
||||
|
||||
DT:RegisterPanel(lchatdp, 3, "ANCHOR_TOPLEFT", -17, 4)
|
||||
|
||||
--Left Chat Toggle Button
|
||||
local lchattb = CreateFrame("Button", "LeftChatToggleButton", E.UIParent)
|
||||
lchattb.parent = lchat
|
||||
LeftChatPanel.fadeFunc = ChatPanelLeft_OnFade
|
||||
lchattb:Point("TOPRIGHT", lchatdp, "TOPLEFT", E.Border - E.Spacing*3, 0)
|
||||
lchattb:Point("TOPLEFT", lchatdp, "TOPLEFT", -E.Border - E.Spacing*3 - SIDE_BUTTON_WIDTH, 0)
|
||||
lchattb:Point("BOTTOMLEFT", lchat, "BOTTOMLEFT", SPACING, SPACING)
|
||||
lchattb:Point("BOTTOMRIGHT", lchat, "BOTTOMLEFT", SPACING+SIDE_BUTTON_WIDTH, SPACING)
|
||||
lchattb:SetTemplate(E.db.datatexts.panelTransparency and "Transparent" or "Default", true)
|
||||
lchattb:RegisterForClicks("AnyUp")
|
||||
lchattb:SetScript("OnEnter", ChatButton_OnEnter)
|
||||
lchattb:SetScript("OnLeave", ChatButton_OnLeave)
|
||||
lchattb:SetScript("OnClick", ChatButton_OnClick)
|
||||
lchattb.text = lchattb:CreateFontString(nil, "OVERLAY")
|
||||
lchattb.text:FontTemplate()
|
||||
lchattb.text:Point("CENTER")
|
||||
lchattb.text:SetJustifyH("CENTER")
|
||||
lchattb.text:SetText("<")
|
||||
|
||||
--Right Chat
|
||||
local rchat = CreateFrame("Frame", "RightChatPanel", E.UIParent)
|
||||
rchat:SetFrameStrata("BACKGROUND")
|
||||
rchat:SetFrameLevel(100)
|
||||
rchat:Size(E.db.chat.separateSizes and E.db.chat.panelWidthRight or E.db.chat.panelWidth, E.db.chat.separateSizes and E.db.chat.panelHeightRight or E.db.chat.panelHeight)
|
||||
rchat:Point("BOTTOMRIGHT", E.UIParent, -4, 4)
|
||||
rchat:CreateBackdrop("Transparent")
|
||||
rchat.backdrop.ignoreBackdropColors = true
|
||||
rchat.backdrop:SetAllPoints()
|
||||
E:CreateMover(rchat, "RightChatMover", L["Right Chat"], nil, nil, nil, nil, nil, "chat,general")
|
||||
|
||||
--Background Texture
|
||||
rchat.tex = rchat:CreateTexture(nil, "OVERLAY")
|
||||
rchat.tex:SetInside()
|
||||
rchat.tex:SetTexture(E.db.chat.panelBackdropNameRight)
|
||||
rchat.tex:SetAlpha(E.db.general.backdropfadecolor.a - 0.7 > 0 and E.db.general.backdropfadecolor.a - 0.7 or 0.5)
|
||||
|
||||
--Right Chat Tab
|
||||
local rchattab = CreateFrame("Frame", "RightChatTab", rchat)
|
||||
rchattab:Point("TOPRIGHT", rchat, "TOPRIGHT", -SPACING, -SPACING)
|
||||
rchattab:Point("TOPLEFT", rchat, "TOPLEFT", SPACING, -SPACING)
|
||||
rchattab:Point("BOTTOMLEFT", rchat, "TOPLEFT", SPACING, -(SPACING + PANEL_HEIGHT))
|
||||
rchattab:Point("BOTTOMRIGHT", rchat, "TOPRIGHT", -SPACING, -(SPACING + PANEL_HEIGHT))
|
||||
rchattab:SetTemplate(E.db.chat.panelTabTransparency and "Transparent" or "Default", true)
|
||||
|
||||
--Right Chat Data Panel
|
||||
local rchatdp = CreateFrame("Frame", "RightChatDataPanel", rchat)
|
||||
rchatdp:Point("BOTTOMLEFT", rchat, "BOTTOMLEFT", SPACING, SPACING)
|
||||
rchatdp:Point("BOTTOMRIGHT", rchat, "BOTTOMRIGHT", -SPACING-SIDE_BUTTON_WIDTH, SPACING)
|
||||
rchatdp:Point("TOPRIGHT", rchat, "BOTTOMRIGHT", -(SIDE_BUTTON_SPACING + SIDE_BUTTON_WIDTH), SPACING + PANEL_HEIGHT)
|
||||
rchatdp:Point("TOPLEFT", rchat, "BOTTOMLEFT", (SPACING), SPACING + PANEL_HEIGHT)
|
||||
rchatdp:SetTemplate(E.db.datatexts.panelTransparency and "Transparent" or "Default", true)
|
||||
DT:RegisterPanel(rchatdp, 3, "ANCHOR_TOPRIGHT", 17, 4)
|
||||
|
||||
--Right Chat Toggle Button
|
||||
local rchattb = CreateFrame("Button", "RightChatToggleButton", E.UIParent)
|
||||
rchattb.parent = rchat
|
||||
rchat.fadeFunc = ChatPanelRight_OnFade
|
||||
rchattb:Point("TOPLEFT", rchatdp, "TOPRIGHT", -E.Border + E.Spacing*3, 0)
|
||||
rchattb:Point("TOPRIGHT", rchatdp, "TOPRIGHT", E.Border + E.Spacing*3 + SIDE_BUTTON_WIDTH, 0)
|
||||
rchattb:Point("BOTTOMRIGHT", rchat, "BOTTOMRIGHT", -SPACING, SPACING)
|
||||
rchattb:Point("BOTTOMLEFT", rchat, "BOTTOMRIGHT", -SPACING-SIDE_BUTTON_WIDTH, SPACING)
|
||||
rchattb:SetTemplate(E.db.datatexts.panelTransparency and "Transparent" or "Default", true)
|
||||
rchattb:RegisterForClicks("AnyUp")
|
||||
rchattb:SetScript("OnEnter", ChatButton_OnEnter)
|
||||
rchattb:SetScript("OnLeave", ChatButton_OnLeave)
|
||||
rchattb:SetScript("OnClick", ChatButton_OnClick)
|
||||
rchattb.text = rchattb:CreateFontString(nil, "OVERLAY")
|
||||
rchattb.text:FontTemplate()
|
||||
rchattb.text:Point("CENTER")
|
||||
rchattb.text:SetJustifyH("CENTER")
|
||||
rchattb.text:SetText(">")
|
||||
|
||||
--Load Settings
|
||||
local fadeToggle = E.db.chat.fadeChatToggles
|
||||
if E.db.LeftChatPanelFaded then
|
||||
if fadeToggle then
|
||||
LeftChatToggleButton:SetAlpha(0)
|
||||
end
|
||||
|
||||
lchat:Hide()
|
||||
end
|
||||
|
||||
if E.db.RightChatPanelFaded then
|
||||
if fadeToggle then
|
||||
RightChatToggleButton:SetAlpha(0)
|
||||
end
|
||||
|
||||
rchat:Hide()
|
||||
end
|
||||
|
||||
self:ToggleChatPanels()
|
||||
end
|
||||
|
||||
function LO:CreateMinimapPanels()
|
||||
local lminipanel = CreateFrame("Frame", "LeftMiniPanel", Minimap)
|
||||
lminipanel:Point("TOPLEFT", Minimap, "BOTTOMLEFT", -E.Border, -E.Spacing*3)
|
||||
lminipanel:Point("BOTTOMRIGHT", Minimap, "BOTTOM", 0, -(E.Spacing*3 + PANEL_HEIGHT))
|
||||
lminipanel:SetTemplate(E.db.datatexts.panelTransparency and "Transparent" or "Default", true)
|
||||
DT:RegisterPanel(lminipanel, 1, "ANCHOR_BOTTOMLEFT", lminipanel:GetWidth() * 2, -4)
|
||||
|
||||
local rminipanel = CreateFrame("Frame", "RightMiniPanel", Minimap)
|
||||
rminipanel:Point("TOPRIGHT", Minimap, "BOTTOMRIGHT", E.Border, -(E.Spacing*3))
|
||||
rminipanel:Point("BOTTOMLEFT", lminipanel, "BOTTOMRIGHT", -E.Border + (E.Spacing*3), 0)
|
||||
rminipanel:SetTemplate(E.db.datatexts.panelTransparency and "Transparent" or "Default", true)
|
||||
DT:RegisterPanel(rminipanel, 1, "ANCHOR_BOTTOM", 0, -4)
|
||||
|
||||
if E.db.datatexts.minimapPanels then
|
||||
LeftMiniPanel:Show()
|
||||
RightMiniPanel:Show()
|
||||
else
|
||||
LeftMiniPanel:Hide()
|
||||
RightMiniPanel:Hide()
|
||||
end
|
||||
|
||||
local configtoggle = CreateFrame("Button", "ElvConfigToggle", Minimap)
|
||||
if E.db.general.reminder.position == "LEFT" then
|
||||
configtoggle:Point("TOPRIGHT", lminipanel, "TOPLEFT", (E.PixelMode and 1 or -1), 0)
|
||||
configtoggle:Point("BOTTOMRIGHT", lminipanel, "BOTTOMLEFT", (E.PixelMode and 1 or -1), 0)
|
||||
else
|
||||
configtoggle:Point("TOPLEFT", rminipanel, "TOPRIGHT", (E.PixelMode and -1 or 1), 0)
|
||||
configtoggle:Point("BOTTOMLEFT", rminipanel, "BOTTOMRIGHT", (E.PixelMode and -1 or 1), 0)
|
||||
end
|
||||
configtoggle:RegisterForClicks("AnyUp")
|
||||
configtoggle:Width(E.RBRWidth)
|
||||
configtoggle:SetTemplate(E.db.datatexts.panelTransparency and "Transparent" or "Default", true)
|
||||
configtoggle.text = configtoggle:CreateFontString(nil, "OVERLAY")
|
||||
configtoggle.text:FontTemplate(E.Libs.LSM:Fetch("font", E.db.datatexts.font), E.db.datatexts.fontSize, E.db.datatexts.fontOutline)
|
||||
configtoggle.text:SetText("C")
|
||||
configtoggle.text:SetPoint("CENTER")
|
||||
configtoggle.text:SetJustifyH("CENTER")
|
||||
configtoggle:SetScript("OnClick", function(_, btn)
|
||||
if btn == "LeftButton" then
|
||||
E:ToggleOptionsUI()
|
||||
else
|
||||
E:BGStats()
|
||||
end
|
||||
end)
|
||||
configtoggle:SetScript("OnEnter", function(self)
|
||||
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT", 0, -4)
|
||||
GameTooltip:ClearLines()
|
||||
GameTooltip:AddDoubleLine(L["Left Click:"], L["Toggle Configuration"], 1, 1, 1)
|
||||
|
||||
if E.db.datatexts.battleground then
|
||||
GameTooltip:AddDoubleLine(L["Right Click:"], L["Show BG Texts"], 1, 1, 1)
|
||||
end
|
||||
GameTooltip:Show()
|
||||
end)
|
||||
configtoggle:SetScript("OnLeave", function()
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
|
||||
local f = CreateFrame("Frame", "BottomMiniPanel", Minimap)
|
||||
f:SetPoint("BOTTOM", Minimap, "BOTTOM")
|
||||
f:Width(120)
|
||||
f:Height(20)
|
||||
f:SetFrameLevel(Minimap:GetFrameLevel() + 5)
|
||||
DT:RegisterPanel(f, 1, "ANCHOR_BOTTOM", 0, -10)
|
||||
|
||||
f = CreateFrame("Frame", "TopMiniPanel", Minimap)
|
||||
f:SetPoint("TOP", Minimap, "TOP")
|
||||
f:Width(120)
|
||||
f:Height(20)
|
||||
f:SetFrameLevel(Minimap:GetFrameLevel() + 5)
|
||||
DT:RegisterPanel(f, 1, "ANCHOR_BOTTOM", 0, -10)
|
||||
|
||||
f = CreateFrame("Frame", "TopLeftMiniPanel", Minimap)
|
||||
f:SetPoint("TOPLEFT", Minimap, "TOPLEFT")
|
||||
f:Width(75)
|
||||
f:Height(20)
|
||||
f:SetFrameLevel(Minimap:GetFrameLevel() + 5)
|
||||
DT:RegisterPanel(f, 1, "ANCHOR_BOTTOMLEFT", 0, -10)
|
||||
|
||||
f = CreateFrame("Frame", "TopRightMiniPanel", Minimap)
|
||||
f:SetPoint("TOPRIGHT", Minimap, "TOPRIGHT")
|
||||
f:Width(75)
|
||||
f:Height(20)
|
||||
f:SetFrameLevel(Minimap:GetFrameLevel() + 5)
|
||||
DT:RegisterPanel(f, 1, "ANCHOR_BOTTOMRIGHT", 0, -10)
|
||||
|
||||
f = CreateFrame("Frame", "BottomLeftMiniPanel", Minimap)
|
||||
f:SetPoint("BOTTOMLEFT", Minimap, "BOTTOMLEFT")
|
||||
f:Width(75)
|
||||
f:Height(20)
|
||||
f:SetFrameLevel(Minimap:GetFrameLevel() + 5)
|
||||
DT:RegisterPanel(f, 1, "ANCHOR_BOTTOMLEFT", 0, -10)
|
||||
|
||||
f = CreateFrame("Frame", "BottomRightMiniPanel", Minimap)
|
||||
f:SetPoint("BOTTOMRIGHT", Minimap, "BOTTOMRIGHT")
|
||||
f:Width(75)
|
||||
f:Height(20)
|
||||
f:SetFrameLevel(Minimap:GetFrameLevel() + 5)
|
||||
DT:RegisterPanel(f, 1, "ANCHOR_BOTTOMRIGHT", 0, -10)
|
||||
end
|
||||
|
||||
local function InitializeCallback()
|
||||
LO:Initialize()
|
||||
end
|
||||
|
||||
E:RegisterModule(LO:GetName(), InitializeCallback)
|
||||
@@ -0,0 +1,3 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||
<Script file="Layout.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,674 @@
|
||||
--- **AceAddon-3.0** provides a template for creating addon objects.
|
||||
-- It'll provide you with a set of callback functions that allow you to simplify the loading
|
||||
-- process of your addon.\\
|
||||
-- Callbacks provided are:\\
|
||||
-- * **OnInitialize**, which is called directly after the addon is fully loaded.
|
||||
-- * **OnEnable** which gets called during the PLAYER_LOGIN event, when most of the data provided by the game is already present.
|
||||
-- * **OnDisable**, which is only called when your addon is manually being disabled.
|
||||
-- @usage
|
||||
-- -- A small (but complete) addon, that doesn't do anything,
|
||||
-- -- but shows usage of the callbacks.
|
||||
-- local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
|
||||
--
|
||||
-- function MyAddon:OnInitialize()
|
||||
-- -- do init tasks here, like loading the Saved Variables,
|
||||
-- -- or setting up slash commands.
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Do more initialization here, that really enables the use of your addon.
|
||||
-- -- Register Events, Hook functions, Create Frames, Get information from
|
||||
-- -- the game that wasn't available in OnInitialize
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:OnDisable()
|
||||
-- -- Unhook, Unregister Events, Hide frames that you created.
|
||||
-- -- You would probably only use an OnDisable if you want to
|
||||
-- -- build a "standby" mode, or be able to toggle modules on/off.
|
||||
-- end
|
||||
-- @class file
|
||||
-- @name AceAddon-3.0.lua
|
||||
-- @release $Id$
|
||||
|
||||
local MAJOR, MINOR = "AceAddon-3.0", 12
|
||||
local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceAddon then return end -- No Upgrade needed.
|
||||
|
||||
AceAddon.frame = AceAddon.frame or CreateFrame("Frame", "AceAddon30Frame") -- Our very own frame
|
||||
AceAddon.addons = AceAddon.addons or {} -- addons in general
|
||||
AceAddon.statuses = AceAddon.statuses or {} -- statuses of addon.
|
||||
AceAddon.initializequeue = AceAddon.initializequeue or {} -- addons that are new and not initialized
|
||||
AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized and waiting to be enabled
|
||||
AceAddon.embeds = AceAddon.embeds or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) -- contains a list of libraries embedded in an addon
|
||||
|
||||
-- Lua APIs
|
||||
local tinsert, tconcat, tremove = table.insert, table.concat, table.remove
|
||||
local fmt, tostring = string.format, tostring
|
||||
local select, pairs, next, type, unpack = select, pairs, next, type, unpack
|
||||
local loadstring, assert, error = loadstring, assert, error
|
||||
local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: LibStub, IsLoggedIn, geterrorhandler
|
||||
|
||||
--[[
|
||||
xpcall safecall implementation
|
||||
]]
|
||||
local xpcall = xpcall
|
||||
|
||||
local function errorhandler(err)
|
||||
return geterrorhandler()(err)
|
||||
end
|
||||
|
||||
local function CreateDispatcher(argCount)
|
||||
local code = [[
|
||||
local xpcall, eh = ...
|
||||
local method, ARGS
|
||||
local function call() return method(ARGS) end
|
||||
|
||||
local function dispatch(func, ...)
|
||||
method = func
|
||||
if not method then return end
|
||||
ARGS = ...
|
||||
return xpcall(call, eh)
|
||||
end
|
||||
|
||||
return dispatch
|
||||
]]
|
||||
|
||||
local ARGS = {}
|
||||
for i = 1, argCount do ARGS[i] = "arg"..i end
|
||||
code = code:gsub("ARGS", tconcat(ARGS, ", "))
|
||||
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
|
||||
end
|
||||
|
||||
local Dispatchers = setmetatable({}, {__index=function(self, argCount)
|
||||
local dispatcher = CreateDispatcher(argCount)
|
||||
rawset(self, argCount, dispatcher)
|
||||
return dispatcher
|
||||
end})
|
||||
Dispatchers[0] = function(func)
|
||||
return xpcall(func, errorhandler)
|
||||
end
|
||||
|
||||
local function safecall(func, ...)
|
||||
-- we check to see if the func is passed is actually a function here and don't error when it isn't
|
||||
-- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not
|
||||
-- present execution should continue without hinderance
|
||||
if type(func) == "function" then
|
||||
return Dispatchers[select('#', ...)](func, ...)
|
||||
end
|
||||
end
|
||||
|
||||
-- local functions that will be implemented further down
|
||||
local Enable, Disable, EnableModule, DisableModule, Embed, NewModule, GetModule, GetName, SetDefaultModuleState, SetDefaultModuleLibraries, SetEnabledState, SetDefaultModulePrototype
|
||||
|
||||
-- used in the addon metatable
|
||||
local function addontostring( self ) return self.name end
|
||||
|
||||
-- Check if the addon is queued for initialization
|
||||
local function queuedForInitialization(addon)
|
||||
for i = 1, #AceAddon.initializequeue do
|
||||
if AceAddon.initializequeue[i] == addon then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Create a new AceAddon-3.0 addon.
|
||||
-- Any libraries you specified will be embeded, and the addon will be scheduled for
|
||||
-- its OnInitialize and OnEnable callbacks.
|
||||
-- The final addon object, with all libraries embeded, will be returned.
|
||||
-- @paramsig [object ,]name[, lib, ...]
|
||||
-- @param object Table to use as a base for the addon (optional)
|
||||
-- @param name Name of the addon object to create
|
||||
-- @param lib List of libraries to embed into the addon
|
||||
-- @usage
|
||||
-- -- Create a simple addon object
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0")
|
||||
--
|
||||
-- -- Create a Addon object based on the table of a frame
|
||||
-- local MyFrame = CreateFrame("Frame")
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0")
|
||||
function AceAddon:NewAddon(objectorname, ...)
|
||||
local object,name
|
||||
local i=1
|
||||
if type(objectorname)=="table" then
|
||||
object=objectorname
|
||||
name=...
|
||||
i=2
|
||||
else
|
||||
name=objectorname
|
||||
end
|
||||
if type(name)~="string" then
|
||||
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2)
|
||||
end
|
||||
if self.addons[name] then
|
||||
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists."):format(name), 2)
|
||||
end
|
||||
|
||||
object = object or {}
|
||||
object.name = name
|
||||
|
||||
local addonmeta = {}
|
||||
local oldmeta = getmetatable(object)
|
||||
if oldmeta then
|
||||
for k, v in pairs(oldmeta) do addonmeta[k] = v end
|
||||
end
|
||||
addonmeta.__tostring = addontostring
|
||||
|
||||
setmetatable( object, addonmeta )
|
||||
self.addons[name] = object
|
||||
object.modules = {}
|
||||
object.orderedModules = {}
|
||||
object.defaultModuleLibraries = {}
|
||||
Embed( object ) -- embed NewModule, GetModule methods
|
||||
self:EmbedLibraries(object, select(i,...))
|
||||
|
||||
-- add to queue of addons to be initialized upon ADDON_LOADED
|
||||
tinsert(self.initializequeue, object)
|
||||
return object
|
||||
end
|
||||
|
||||
|
||||
--- Get the addon object by its name from the internal AceAddon registry.
|
||||
-- Throws an error if the addon object cannot be found (except if silent is set).
|
||||
-- @param name unique name of the addon object
|
||||
-- @param silent if true, the addon is optional, silently return nil if its not found
|
||||
-- @usage
|
||||
-- -- Get the Addon
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
function AceAddon:GetAddon(name, silent)
|
||||
if not silent and not self.addons[name] then
|
||||
error(("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'."):format(tostring(name)), 2)
|
||||
end
|
||||
return self.addons[name]
|
||||
end
|
||||
|
||||
-- - Embed a list of libraries into the specified addon.
|
||||
-- This function will try to embed all of the listed libraries into the addon
|
||||
-- and error if a single one fails.
|
||||
--
|
||||
-- **Note:** This function is for internal use by :NewAddon/:NewModule
|
||||
-- @paramsig addon, [lib, ...]
|
||||
-- @param addon addon object to embed the libs in
|
||||
-- @param lib List of libraries to embed into the addon
|
||||
function AceAddon:EmbedLibraries(addon, ...)
|
||||
for i=1,select("#", ... ) do
|
||||
local libname = select(i, ...)
|
||||
self:EmbedLibrary(addon, libname, false, 4)
|
||||
end
|
||||
end
|
||||
|
||||
-- - Embed a library into the addon object.
|
||||
-- This function will check if the specified library is registered with LibStub
|
||||
-- and if it has a :Embed function to call. It'll error if any of those conditions
|
||||
-- fails.
|
||||
--
|
||||
-- **Note:** This function is for internal use by :EmbedLibraries
|
||||
-- @paramsig addon, libname[, silent[, offset]]
|
||||
-- @param addon addon object to embed the library in
|
||||
-- @param libname name of the library to embed
|
||||
-- @param silent marks an embed to fail silently if the library doesn't exist (optional)
|
||||
-- @param offset will push the error messages back to said offset, defaults to 2 (optional)
|
||||
function AceAddon:EmbedLibrary(addon, libname, silent, offset)
|
||||
local lib = LibStub:GetLibrary(libname, true)
|
||||
if not lib and not silent then
|
||||
error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q."):format(tostring(libname)), offset or 2)
|
||||
elseif lib and type(lib.Embed) == "function" then
|
||||
lib:Embed(addon)
|
||||
tinsert(self.embeds[addon], libname)
|
||||
return true
|
||||
elseif lib then
|
||||
error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable"):format(libname), offset or 2)
|
||||
end
|
||||
end
|
||||
|
||||
--- Return the specified module from an addon object.
|
||||
-- Throws an error if the addon object cannot be found (except if silent is set)
|
||||
-- @name //addon//:GetModule
|
||||
-- @paramsig name[, silent]
|
||||
-- @param name unique name of the module
|
||||
-- @param silent if true, the module is optional, silently return nil if its not found (optional)
|
||||
-- @usage
|
||||
-- -- Get the Addon
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- -- Get the Module
|
||||
-- MyModule = MyAddon:GetModule("MyModule")
|
||||
function GetModule(self, name, silent)
|
||||
if not self.modules[name] and not silent then
|
||||
error(("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'."):format(tostring(name)), 2)
|
||||
end
|
||||
return self.modules[name]
|
||||
end
|
||||
|
||||
local function IsModuleTrue(self) return true end
|
||||
|
||||
--- Create a new module for the addon.
|
||||
-- The new module can have its own embeded libraries and/or use a module prototype to be mixed into the module.\\
|
||||
-- A module has the same functionality as a real addon, it can have modules of its own, and has the same API as
|
||||
-- an addon object.
|
||||
-- @name //addon//:NewModule
|
||||
-- @paramsig name[, prototype|lib[, lib, ...]]
|
||||
-- @param name unique name of the module
|
||||
-- @param prototype object to derive this module from, methods and values from this table will be mixed into the module (optional)
|
||||
-- @param lib List of libraries to embed into the addon
|
||||
-- @usage
|
||||
-- -- Create a module with some embeded libraries
|
||||
-- MyModule = MyAddon:NewModule("MyModule", "AceEvent-3.0", "AceHook-3.0")
|
||||
--
|
||||
-- -- Create a module with a prototype
|
||||
-- local prototype = { OnEnable = function(self) print("OnEnable called!") end }
|
||||
-- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0")
|
||||
function NewModule(self, name, prototype, ...)
|
||||
if type(name) ~= "string" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) end
|
||||
if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'."):format(type(prototype)), 2) end
|
||||
|
||||
if self.modules[name] then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists."):format(name), 2) end
|
||||
|
||||
-- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well.
|
||||
-- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is.
|
||||
local module = AceAddon:NewAddon(fmt("%s_%s", self.name or tostring(self), name))
|
||||
|
||||
module.IsModule = IsModuleTrue
|
||||
module:SetEnabledState(self.defaultModuleState)
|
||||
module.moduleName = name
|
||||
|
||||
if type(prototype) == "string" then
|
||||
AceAddon:EmbedLibraries(module, prototype, ...)
|
||||
else
|
||||
AceAddon:EmbedLibraries(module, ...)
|
||||
end
|
||||
AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries))
|
||||
|
||||
if not prototype or type(prototype) == "string" then
|
||||
prototype = self.defaultModulePrototype or nil
|
||||
end
|
||||
|
||||
if type(prototype) == "table" then
|
||||
local mt = getmetatable(module)
|
||||
mt.__index = prototype
|
||||
setmetatable(module, mt) -- More of a Base class type feel.
|
||||
end
|
||||
|
||||
safecall(self.OnModuleCreated, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy.
|
||||
self.modules[name] = module
|
||||
tinsert(self.orderedModules, module)
|
||||
|
||||
return module
|
||||
end
|
||||
|
||||
--- Returns the real name of the addon or module, without any prefix.
|
||||
-- @name //addon//:GetName
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- print(MyAddon:GetName())
|
||||
-- -- prints "MyAddon"
|
||||
function GetName(self)
|
||||
return self.moduleName or self.name
|
||||
end
|
||||
|
||||
--- Enables the Addon, if possible, return true or false depending on success.
|
||||
-- This internally calls AceAddon:EnableAddon(), thus dispatching a OnEnable callback
|
||||
-- and enabling all modules of the addon (unless explicitly disabled).\\
|
||||
-- :Enable() also sets the internal `enableState` variable to true
|
||||
-- @name //addon//:Enable
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- -- Enable MyModule
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyModule = MyAddon:GetModule("MyModule")
|
||||
-- MyModule:Enable()
|
||||
function Enable(self)
|
||||
self:SetEnabledState(true)
|
||||
|
||||
-- nevcairiel 2013-04-27: don't enable an addon/module if its queued for init still
|
||||
-- it'll be enabled after the init process
|
||||
if not queuedForInitialization(self) then
|
||||
return AceAddon:EnableAddon(self)
|
||||
end
|
||||
end
|
||||
|
||||
--- Disables the Addon, if possible, return true or false depending on success.
|
||||
-- This internally calls AceAddon:DisableAddon(), thus dispatching a OnDisable callback
|
||||
-- and disabling all modules of the addon.\\
|
||||
-- :Disable() also sets the internal `enableState` variable to false
|
||||
-- @name //addon//:Disable
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- -- Disable MyAddon
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyAddon:Disable()
|
||||
function Disable(self)
|
||||
self:SetEnabledState(false)
|
||||
return AceAddon:DisableAddon(self)
|
||||
end
|
||||
|
||||
--- Enables the Module, if possible, return true or false depending on success.
|
||||
-- Short-hand function that retrieves the module via `:GetModule` and calls `:Enable` on the module object.
|
||||
-- @name //addon//:EnableModule
|
||||
-- @paramsig name
|
||||
-- @usage
|
||||
-- -- Enable MyModule using :GetModule
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyModule = MyAddon:GetModule("MyModule")
|
||||
-- MyModule:Enable()
|
||||
--
|
||||
-- -- Enable MyModule using the short-hand
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyAddon:EnableModule("MyModule")
|
||||
function EnableModule(self, name)
|
||||
local module = self:GetModule( name )
|
||||
return module:Enable()
|
||||
end
|
||||
|
||||
--- Disables the Module, if possible, return true or false depending on success.
|
||||
-- Short-hand function that retrieves the module via `:GetModule` and calls `:Disable` on the module object.
|
||||
-- @name //addon//:DisableModule
|
||||
-- @paramsig name
|
||||
-- @usage
|
||||
-- -- Disable MyModule using :GetModule
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyModule = MyAddon:GetModule("MyModule")
|
||||
-- MyModule:Disable()
|
||||
--
|
||||
-- -- Disable MyModule using the short-hand
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyAddon:DisableModule("MyModule")
|
||||
function DisableModule(self, name)
|
||||
local module = self:GetModule( name )
|
||||
return module:Disable()
|
||||
end
|
||||
|
||||
--- Set the default libraries to be mixed into all modules created by this object.
|
||||
-- Note that you can only change the default module libraries before any module is created.
|
||||
-- @name //addon//:SetDefaultModuleLibraries
|
||||
-- @paramsig lib[, lib, ...]
|
||||
-- @param lib List of libraries to embed into the addon
|
||||
-- @usage
|
||||
-- -- Create the addon object
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
|
||||
-- -- Configure default libraries for modules (all modules need AceEvent-3.0)
|
||||
-- MyAddon:SetDefaultModuleLibraries("AceEvent-3.0")
|
||||
-- -- Create a module
|
||||
-- MyModule = MyAddon:NewModule("MyModule")
|
||||
function SetDefaultModuleLibraries(self, ...)
|
||||
if next(self.modules) then
|
||||
error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2)
|
||||
end
|
||||
self.defaultModuleLibraries = {...}
|
||||
end
|
||||
|
||||
--- Set the default state in which new modules are being created.
|
||||
-- Note that you can only change the default state before any module is created.
|
||||
-- @name //addon//:SetDefaultModuleState
|
||||
-- @paramsig state
|
||||
-- @param state Default state for new modules, true for enabled, false for disabled
|
||||
-- @usage
|
||||
-- -- Create the addon object
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
|
||||
-- -- Set the default state to "disabled"
|
||||
-- MyAddon:SetDefaultModuleState(false)
|
||||
-- -- Create a module and explicilty enable it
|
||||
-- MyModule = MyAddon:NewModule("MyModule")
|
||||
-- MyModule:Enable()
|
||||
function SetDefaultModuleState(self, state)
|
||||
if next(self.modules) then
|
||||
error("Usage: SetDefaultModuleState(state): cannot change the module defaults after a module has been registered.", 2)
|
||||
end
|
||||
self.defaultModuleState = state
|
||||
end
|
||||
|
||||
--- Set the default prototype to use for new modules on creation.
|
||||
-- Note that you can only change the default prototype before any module is created.
|
||||
-- @name //addon//:SetDefaultModulePrototype
|
||||
-- @paramsig prototype
|
||||
-- @param prototype Default prototype for the new modules (table)
|
||||
-- @usage
|
||||
-- -- Define a prototype
|
||||
-- local prototype = { OnEnable = function(self) print("OnEnable called!") end }
|
||||
-- -- Set the default prototype
|
||||
-- MyAddon:SetDefaultModulePrototype(prototype)
|
||||
-- -- Create a module and explicitly Enable it
|
||||
-- MyModule = MyAddon:NewModule("MyModule")
|
||||
-- MyModule:Enable()
|
||||
-- -- should print "OnEnable called!" now
|
||||
-- @see NewModule
|
||||
function SetDefaultModulePrototype(self, prototype)
|
||||
if next(self.modules) then
|
||||
error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2)
|
||||
end
|
||||
if type(prototype) ~= "table" then
|
||||
error(("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'."):format(type(prototype)), 2)
|
||||
end
|
||||
self.defaultModulePrototype = prototype
|
||||
end
|
||||
|
||||
--- Set the state of an addon or module
|
||||
-- This should only be called before any enabling actually happend, e.g. in/before OnInitialize.
|
||||
-- @name //addon//:SetEnabledState
|
||||
-- @paramsig state
|
||||
-- @param state the state of an addon or module (enabled=true, disabled=false)
|
||||
function SetEnabledState(self, state)
|
||||
self.enabledState = state
|
||||
end
|
||||
|
||||
|
||||
--- Return an iterator of all modules associated to the addon.
|
||||
-- @name //addon//:IterateModules
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- -- Enable all modules
|
||||
-- for name, module in MyAddon:IterateModules() do
|
||||
-- module:Enable()
|
||||
-- end
|
||||
local function IterateModules(self) return pairs(self.modules) end
|
||||
|
||||
-- Returns an iterator of all embeds in the addon
|
||||
-- @name //addon//:IterateEmbeds
|
||||
-- @paramsig
|
||||
local function IterateEmbeds(self) return pairs(AceAddon.embeds[self]) end
|
||||
|
||||
--- Query the enabledState of an addon.
|
||||
-- @name //addon//:IsEnabled
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- if MyAddon:IsEnabled() then
|
||||
-- MyAddon:Disable()
|
||||
-- end
|
||||
local function IsEnabled(self) return self.enabledState end
|
||||
local mixins = {
|
||||
NewModule = NewModule,
|
||||
GetModule = GetModule,
|
||||
Enable = Enable,
|
||||
Disable = Disable,
|
||||
EnableModule = EnableModule,
|
||||
DisableModule = DisableModule,
|
||||
IsEnabled = IsEnabled,
|
||||
SetDefaultModuleLibraries = SetDefaultModuleLibraries,
|
||||
SetDefaultModuleState = SetDefaultModuleState,
|
||||
SetDefaultModulePrototype = SetDefaultModulePrototype,
|
||||
SetEnabledState = SetEnabledState,
|
||||
IterateModules = IterateModules,
|
||||
IterateEmbeds = IterateEmbeds,
|
||||
GetName = GetName,
|
||||
}
|
||||
local function IsModule(self) return false end
|
||||
local pmixins = {
|
||||
defaultModuleState = true,
|
||||
enabledState = true,
|
||||
IsModule = IsModule,
|
||||
}
|
||||
-- Embed( target )
|
||||
-- target (object) - target object to embed aceaddon in
|
||||
--
|
||||
-- this is a local function specifically since it's meant to be only called internally
|
||||
function Embed(target, skipPMixins)
|
||||
for k, v in pairs(mixins) do
|
||||
target[k] = v
|
||||
end
|
||||
if not skipPMixins then
|
||||
for k, v in pairs(pmixins) do
|
||||
target[k] = target[k] or v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- - Initialize the addon after creation.
|
||||
-- This function is only used internally during the ADDON_LOADED event
|
||||
-- It will call the **OnInitialize** function on the addon object (if present),
|
||||
-- and the **OnEmbedInitialize** function on all embeded libraries.
|
||||
--
|
||||
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
|
||||
-- @param addon addon object to intialize
|
||||
function AceAddon:InitializeAddon(addon)
|
||||
safecall(addon.OnInitialize, addon)
|
||||
|
||||
local embeds = self.embeds[addon]
|
||||
for i = 1, #embeds do
|
||||
local lib = LibStub:GetLibrary(embeds[i], true)
|
||||
if lib then safecall(lib.OnEmbedInitialize, lib, addon) end
|
||||
end
|
||||
|
||||
-- we don't call InitializeAddon on modules specifically, this is handled
|
||||
-- from the event handler and only done _once_
|
||||
end
|
||||
|
||||
-- - Enable the addon after creation.
|
||||
-- Note: This function is only used internally during the PLAYER_LOGIN event, or during ADDON_LOADED,
|
||||
-- if IsLoggedIn() already returns true at that point, e.g. for LoD Addons.
|
||||
-- It will call the **OnEnable** function on the addon object (if present),
|
||||
-- and the **OnEmbedEnable** function on all embeded libraries.\\
|
||||
-- This function does not toggle the enable state of the addon itself, and will return early if the addon is disabled.
|
||||
--
|
||||
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
|
||||
-- Use :Enable on the addon itself instead.
|
||||
-- @param addon addon object to enable
|
||||
function AceAddon:EnableAddon(addon)
|
||||
if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end
|
||||
if self.statuses[addon.name] or not addon.enabledState then return false end
|
||||
|
||||
-- set the statuses first, before calling the OnEnable. this allows for Disabling of the addon in OnEnable.
|
||||
self.statuses[addon.name] = true
|
||||
|
||||
safecall(addon.OnEnable, addon)
|
||||
|
||||
-- make sure we're still enabled before continueing
|
||||
if self.statuses[addon.name] then
|
||||
local embeds = self.embeds[addon]
|
||||
for i = 1, #embeds do
|
||||
local lib = LibStub:GetLibrary(embeds[i], true)
|
||||
if lib then safecall(lib.OnEmbedEnable, lib, addon) end
|
||||
end
|
||||
|
||||
-- enable possible modules.
|
||||
local modules = addon.orderedModules
|
||||
for i = 1, #modules do
|
||||
self:EnableAddon(modules[i])
|
||||
end
|
||||
end
|
||||
return self.statuses[addon.name] -- return true if we're disabled
|
||||
end
|
||||
|
||||
-- - Disable the addon
|
||||
-- Note: This function is only used internally.
|
||||
-- It will call the **OnDisable** function on the addon object (if present),
|
||||
-- and the **OnEmbedDisable** function on all embeded libraries.\\
|
||||
-- This function does not toggle the enable state of the addon itself, and will return early if the addon is still enabled.
|
||||
--
|
||||
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
|
||||
-- Use :Disable on the addon itself instead.
|
||||
-- @param addon addon object to enable
|
||||
function AceAddon:DisableAddon(addon)
|
||||
if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end
|
||||
if not self.statuses[addon.name] then return false end
|
||||
|
||||
-- set statuses first before calling OnDisable, this allows for aborting the disable in OnDisable.
|
||||
self.statuses[addon.name] = false
|
||||
|
||||
safecall( addon.OnDisable, addon )
|
||||
|
||||
-- make sure we're still disabling...
|
||||
if not self.statuses[addon.name] then
|
||||
local embeds = self.embeds[addon]
|
||||
for i = 1, #embeds do
|
||||
local lib = LibStub:GetLibrary(embeds[i], true)
|
||||
if lib then safecall(lib.OnEmbedDisable, lib, addon) end
|
||||
end
|
||||
-- disable possible modules.
|
||||
local modules = addon.orderedModules
|
||||
for i = 1, #modules do
|
||||
self:DisableAddon(modules[i])
|
||||
end
|
||||
end
|
||||
|
||||
return not self.statuses[addon.name] -- return true if we're disabled
|
||||
end
|
||||
|
||||
--- Get an iterator over all registered addons.
|
||||
-- @usage
|
||||
-- -- Print a list of all installed AceAddon's
|
||||
-- for name, addon in AceAddon:IterateAddons() do
|
||||
-- print("Addon: " .. name)
|
||||
-- end
|
||||
function AceAddon:IterateAddons() return pairs(self.addons) end
|
||||
|
||||
--- Get an iterator over the internal status registry.
|
||||
-- @usage
|
||||
-- -- Print a list of all enabled addons
|
||||
-- for name, status in AceAddon:IterateAddonStatus() do
|
||||
-- if status then
|
||||
-- print("EnabledAddon: " .. name)
|
||||
-- end
|
||||
-- end
|
||||
function AceAddon:IterateAddonStatus() return pairs(self.statuses) end
|
||||
|
||||
-- Following Iterators are deprecated, and their addon specific versions should be used
|
||||
-- e.g. addon:IterateEmbeds() instead of :IterateEmbedsOnAddon(addon)
|
||||
function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) end
|
||||
function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end
|
||||
|
||||
-- Event Handling
|
||||
local function onEvent(this, event, arg1)
|
||||
-- 2011-08-17 nevcairiel - ignore the load event of Blizzard_DebugTools, so a potential startup error isn't swallowed up
|
||||
if (event == "ADDON_LOADED" and arg1 ~= "Blizzard_DebugTools") or event == "PLAYER_LOGIN" then
|
||||
-- if a addon loads another addon, recursion could happen here, so we need to validate the table on every iteration
|
||||
while(#AceAddon.initializequeue > 0) do
|
||||
local addon = tremove(AceAddon.initializequeue, 1)
|
||||
-- this might be an issue with recursion - TODO: validate
|
||||
if event == "ADDON_LOADED" then addon.baseName = arg1 end
|
||||
AceAddon:InitializeAddon(addon)
|
||||
tinsert(AceAddon.enablequeue, addon)
|
||||
end
|
||||
|
||||
if IsLoggedIn() then
|
||||
while(#AceAddon.enablequeue > 0) do
|
||||
local addon = tremove(AceAddon.enablequeue, 1)
|
||||
AceAddon:EnableAddon(addon)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
AceAddon.frame:RegisterEvent("ADDON_LOADED")
|
||||
AceAddon.frame:RegisterEvent("PLAYER_LOGIN")
|
||||
AceAddon.frame:SetScript("OnEvent", onEvent)
|
||||
|
||||
-- upgrade embeded
|
||||
for name, addon in pairs(AceAddon.addons) do
|
||||
Embed(addon, true)
|
||||
end
|
||||
|
||||
-- 2010-10-27 nevcairiel - add new "orderedModules" table
|
||||
if oldminor and oldminor < 10 then
|
||||
for name, addon in pairs(AceAddon.addons) do
|
||||
addon.orderedModules = {}
|
||||
for module_name, module in pairs(addon.modules) do
|
||||
tinsert(addon.orderedModules, module)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="AceAddon-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,308 @@
|
||||
--- **AceComm-3.0** 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.\\
|
||||
-- **ChatThrottleLib** is of course being used to avoid being disconnected by the server.
|
||||
--
|
||||
-- **AceComm-3.0** can be embeded into your addon, either explicitly by calling AceComm:Embed(MyAddon) or by
|
||||
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
|
||||
-- and can be accessed directly, without having to explicitly call AceComm itself.\\
|
||||
-- It is recommended to embed AceComm, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceComm.
|
||||
-- @class file
|
||||
-- @name AceComm-3.0
|
||||
-- @release $Id$
|
||||
|
||||
--[[ AceComm-3.0
|
||||
|
||||
TODO: Time out old data rotting around from dead senders? Not a HUGE deal since the number of possible sender names is somewhat limited.
|
||||
|
||||
]]
|
||||
|
||||
local CallbackHandler = LibStub("CallbackHandler-1.0")
|
||||
local CTL = assert(ChatThrottleLib, "AceComm-3.0 requires ChatThrottleLib")
|
||||
|
||||
local MAJOR, MINOR = "AceComm-3.0", 12
|
||||
local AceComm,oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceComm then return end
|
||||
|
||||
-- Lua APIs
|
||||
local type, next, pairs, tostring = type, next, pairs, tostring
|
||||
local strsub, strfind = string.sub, string.find
|
||||
local tinsert, tconcat = table.insert, table.concat
|
||||
local error, assert = error, assert
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: LibStub, DEFAULT_CHAT_FRAME, geterrorhandler
|
||||
|
||||
AceComm.embeds = AceComm.embeds or {}
|
||||
|
||||
-- for my sanity and yours, let's give the message type bytes some names
|
||||
local MSG_MULTI_FIRST = "\001"
|
||||
local MSG_MULTI_NEXT = "\002"
|
||||
local MSG_MULTI_LAST = "\003"
|
||||
|
||||
AceComm.multipart_origprefixes = AceComm.multipart_origprefixes or {} -- e.g. "Prefix\001"="Prefix", "Prefix\002"="Prefix"
|
||||
AceComm.multipart_reassemblers = AceComm.multipart_reassemblers or {} -- e.g. "Prefix\001"="OnReceiveMultipartFirst"
|
||||
|
||||
-- the multipart message spool: indexed by a combination of sender+distribution+
|
||||
AceComm.multipart_spool = AceComm.multipart_spool or {}
|
||||
|
||||
--- Register for Addon Traffic on a specified prefix
|
||||
-- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent)
|
||||
-- @param method Callback to call on message reception: Function reference, or method name (string) to call on self. Defaults to "OnCommReceived"
|
||||
function AceComm:RegisterComm(prefix, method)
|
||||
if method == nil then
|
||||
method = "OnCommReceived"
|
||||
end
|
||||
|
||||
return AceComm._RegisterComm(self, prefix, method) -- created by CallbackHandler
|
||||
end
|
||||
|
||||
local warnedPrefix=false
|
||||
|
||||
--- Send a message over the Addon Channel
|
||||
-- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent)
|
||||
-- @param text Data to send, nils (\000) not allowed. Any length.
|
||||
-- @param distribution Addon channel, e.g. "RAID", "GUILD", etc; see SendAddonMessage API
|
||||
-- @param target Destination for some distributions; see SendAddonMessage API
|
||||
-- @param prio OPTIONAL: ChatThrottleLib priority, "BULK", "NORMAL" or "ALERT". Defaults to "NORMAL".
|
||||
-- @param callbackFn OPTIONAL: callback function to be called as each chunk is sent. receives 3 args: the user supplied arg (see next), the number of bytes sent so far, and the number of bytes total to send.
|
||||
-- @param callbackArg: OPTIONAL: first arg to the callback function. nil will be passed if not specified.
|
||||
function AceComm:SendCommMessage(prefix, text, distribution, target, prio, callbackFn, callbackArg)
|
||||
prio = prio or "NORMAL" -- pasta's reference implementation had different prio for singlepart and multipart, but that's a very bad idea since that can easily lead to out-of-sequence delivery!
|
||||
if not( type(prefix)=="string" and
|
||||
type(text)=="string" and
|
||||
type(distribution)=="string" and
|
||||
(target==nil or type(target)=="string" or type(target)=="number") and
|
||||
(prio=="BULK" or prio=="NORMAL" or prio=="ALERT")
|
||||
) then
|
||||
error('Usage: SendCommMessage(addon, "prefix", "text", "distribution"[, "target"[, "prio"[, callbackFn, callbackarg]]])', 2)
|
||||
end
|
||||
|
||||
if strfind(prefix, "[\001-\009]") then
|
||||
if strfind(prefix, "[\001-\003]") then
|
||||
error("SendCommMessage: Characters \\001--\\003 in prefix are reserved for AceComm metadata", 2)
|
||||
elseif not warnedPrefix then
|
||||
-- I have some ideas about future extensions that require more control characters /mikk, 20090808
|
||||
geterrorhandler()("SendCommMessage: Heads-up developers: Characters \\004--\\009 in prefix are reserved for AceComm future extension")
|
||||
warnedPrefix = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local textlen = #text
|
||||
local maxtextlen = 254 - #prefix -- 254 is the max length of prefix + text that can be sent in one message
|
||||
local queueName = prefix..distribution..(target or "")
|
||||
|
||||
local ctlCallback = nil
|
||||
if callbackFn then
|
||||
ctlCallback = function(sent)
|
||||
return callbackFn(callbackArg, sent, textlen)
|
||||
end
|
||||
end
|
||||
|
||||
if textlen <= maxtextlen then
|
||||
-- fits all in one message
|
||||
CTL:SendAddonMessage(prio, prefix, text, distribution, target, queueName, ctlCallback, textlen)
|
||||
else
|
||||
maxtextlen = maxtextlen - 1 -- 1 extra byte for part indicator in prefix
|
||||
|
||||
-- first part
|
||||
local chunk = strsub(text, 1, maxtextlen)
|
||||
CTL:SendAddonMessage(prio, prefix..MSG_MULTI_FIRST, chunk, distribution, target, queueName, ctlCallback, maxtextlen)
|
||||
|
||||
-- continuation
|
||||
local pos = 1+maxtextlen
|
||||
local prefix2 = prefix..MSG_MULTI_NEXT
|
||||
|
||||
while pos+maxtextlen <= textlen do
|
||||
chunk = strsub(text, pos, pos+maxtextlen-1)
|
||||
CTL:SendAddonMessage(prio, prefix2, chunk, distribution, target, queueName, ctlCallback, pos+maxtextlen-1)
|
||||
pos = pos + maxtextlen
|
||||
end
|
||||
|
||||
-- final part
|
||||
chunk = strsub(text, pos)
|
||||
CTL:SendAddonMessage(prio, prefix..MSG_MULTI_LAST, chunk, distribution, target, queueName, ctlCallback, textlen)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- Message receiving
|
||||
----------------------------------------
|
||||
|
||||
do
|
||||
local compost = setmetatable({}, {__mode = "k"})
|
||||
local function new()
|
||||
local t = next(compost)
|
||||
if t then
|
||||
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
|
||||
t[i]=nil
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
return {}
|
||||
end
|
||||
|
||||
local function lostdatawarning(prefix,sender,where)
|
||||
DEFAULT_CHAT_FRAME:AddMessage(MAJOR..": Warning: lost network data regarding '"..tostring(prefix).."' from '"..tostring(sender).."' (in "..where..")")
|
||||
end
|
||||
|
||||
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 spool = AceComm.multipart_spool
|
||||
|
||||
--[[
|
||||
if spool[key] then
|
||||
lostdatawarning(prefix,sender,"First")
|
||||
-- continue and overwrite
|
||||
end
|
||||
--]]
|
||||
|
||||
spool[key] = message -- plain string for now
|
||||
end
|
||||
|
||||
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 spool = AceComm.multipart_spool
|
||||
local olddata = spool[key]
|
||||
|
||||
if not olddata then
|
||||
--lostdatawarning(prefix,sender,"Next")
|
||||
return
|
||||
end
|
||||
|
||||
if type(olddata)~="table" then
|
||||
-- ... but what we have is not a table. So make it one. (Pull a composted one if available)
|
||||
local t = new()
|
||||
t[1] = olddata -- add old data as first string
|
||||
t[2] = message -- and new message as second string
|
||||
spool[key] = t -- and put the table in the spool instead of the old string
|
||||
else
|
||||
tinsert(olddata, message)
|
||||
end
|
||||
end
|
||||
|
||||
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 spool = AceComm.multipart_spool
|
||||
local olddata = spool[key]
|
||||
|
||||
if not olddata then
|
||||
--lostdatawarning(prefix,sender,"End")
|
||||
return
|
||||
end
|
||||
|
||||
spool[key] = nil
|
||||
|
||||
if type(olddata) == "table" then
|
||||
-- if we've received a "next", the spooled data will be a table for rapid & garbage-free tconcat
|
||||
tinsert(olddata, message)
|
||||
AceComm.callbacks:Fire(prefix, tconcat(olddata, ""), distribution, sender)
|
||||
compost[olddata] = true
|
||||
else
|
||||
-- if we've only received a "first", the spooled data will still only be a string
|
||||
AceComm.callbacks:Fire(prefix, olddata..message, distribution, sender)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- Embed CallbackHandler
|
||||
----------------------------------------
|
||||
|
||||
if not AceComm.callbacks then
|
||||
-- ensure that 'prefix to watch' table is consistent with registered
|
||||
-- callbacks
|
||||
AceComm.__prefixes = {}
|
||||
|
||||
AceComm.callbacks = CallbackHandler:New(AceComm,
|
||||
"_RegisterComm",
|
||||
"UnregisterComm",
|
||||
"UnregisterAllComm")
|
||||
end
|
||||
|
||||
function AceComm.callbacks:OnUsed(target, prefix)
|
||||
AceComm.multipart_origprefixes[prefix..MSG_MULTI_FIRST] = prefix
|
||||
AceComm.multipart_reassemblers[prefix..MSG_MULTI_FIRST] = "OnReceiveMultipartFirst"
|
||||
|
||||
AceComm.multipart_origprefixes[prefix..MSG_MULTI_NEXT] = prefix
|
||||
AceComm.multipart_reassemblers[prefix..MSG_MULTI_NEXT] = "OnReceiveMultipartNext"
|
||||
|
||||
AceComm.multipart_origprefixes[prefix..MSG_MULTI_LAST] = prefix
|
||||
AceComm.multipart_reassemblers[prefix..MSG_MULTI_LAST] = "OnReceiveMultipartLast"
|
||||
end
|
||||
|
||||
function AceComm.callbacks:OnUnused(target, prefix)
|
||||
AceComm.multipart_origprefixes[prefix..MSG_MULTI_FIRST] = nil
|
||||
AceComm.multipart_reassemblers[prefix..MSG_MULTI_FIRST] = nil
|
||||
|
||||
AceComm.multipart_origprefixes[prefix..MSG_MULTI_NEXT] = nil
|
||||
AceComm.multipart_reassemblers[prefix..MSG_MULTI_NEXT] = nil
|
||||
|
||||
AceComm.multipart_origprefixes[prefix..MSG_MULTI_LAST] = nil
|
||||
AceComm.multipart_reassemblers[prefix..MSG_MULTI_LAST] = nil
|
||||
end
|
||||
|
||||
local function OnEvent(this, event, ...)
|
||||
if event == "CHAT_MSG_ADDON" then
|
||||
local prefix,message,distribution,sender = ...
|
||||
local reassemblername = AceComm.multipart_reassemblers[prefix]
|
||||
if reassemblername then
|
||||
-- multipart: reassemble
|
||||
local aceCommReassemblerFunc = AceComm[reassemblername]
|
||||
local origprefix = AceComm.multipart_origprefixes[prefix]
|
||||
aceCommReassemblerFunc(AceComm, origprefix, message, distribution, sender)
|
||||
else
|
||||
-- single part: fire it off immediately and let CallbackHandler decide if it's registered or not
|
||||
AceComm.callbacks:Fire(prefix, message, distribution, sender)
|
||||
end
|
||||
else
|
||||
assert(false, "Received "..tostring(event).." event?!")
|
||||
end
|
||||
end
|
||||
|
||||
AceComm.frame = AceComm.frame or CreateFrame("Frame", "AceComm30Frame")
|
||||
AceComm.frame:SetScript("OnEvent", OnEvent)
|
||||
AceComm.frame:UnregisterAllEvents()
|
||||
AceComm.frame:RegisterEvent("CHAT_MSG_ADDON")
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- Base library stuff
|
||||
----------------------------------------
|
||||
|
||||
local mixins = {
|
||||
"RegisterComm",
|
||||
"UnregisterComm",
|
||||
"UnregisterAllComm",
|
||||
"SendCommMessage",
|
||||
}
|
||||
|
||||
-- Embeds AceComm-3.0 into the target object making the functions from the mixins list available on target:..
|
||||
-- @param target target object to embed AceComm-3.0 in
|
||||
function AceComm:Embed(target)
|
||||
for k, v in pairs(mixins) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeds[target] = true
|
||||
return target
|
||||
end
|
||||
|
||||
function AceComm:OnEmbedDisable(target)
|
||||
target:UnregisterAllComm()
|
||||
end
|
||||
|
||||
-- Update embeds
|
||||
for target, v in pairs(AceComm.embeds) do
|
||||
AceComm:Embed(target)
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="ChatThrottleLib.lua"/>
|
||||
<Script file="AceComm-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,517 @@
|
||||
--
|
||||
-- ChatThrottleLib by Mikk
|
||||
--
|
||||
-- Manages AddOn chat output to keep player from getting kicked off.
|
||||
--
|
||||
-- ChatThrottleLib:SendChatMessage/:SendAddonMessage functions that accept
|
||||
-- a Priority ("BULK", "NORMAL", "ALERT") as well as prefix for SendChatMessage.
|
||||
--
|
||||
-- Priorities get an equal share of available bandwidth when fully loaded.
|
||||
-- Communication channels are separated on extension+chattype+destination and
|
||||
-- get round-robinned. (Destination only matters for whispers and channels,
|
||||
-- obviously)
|
||||
--
|
||||
-- Will install hooks for SendChatMessage and SendAddonMessage to measure
|
||||
-- bandwidth bypassing the library and use less bandwidth itself.
|
||||
--
|
||||
--
|
||||
-- Fully embeddable library. Just copy this file into your addon directory,
|
||||
-- add it to the .toc, and it's done.
|
||||
--
|
||||
-- Can run as a standalone addon also, but, really, just embed it! :-)
|
||||
--
|
||||
-- LICENSE: ChatThrottleLib is released into the Public Domain
|
||||
--
|
||||
|
||||
local CTL_VERSION = 24
|
||||
|
||||
local _G = _G
|
||||
|
||||
if _G.ChatThrottleLib then
|
||||
if _G.ChatThrottleLib.version >= CTL_VERSION then
|
||||
-- There's already a newer (or same) version loaded. Buh-bye.
|
||||
return
|
||||
elseif not _G.ChatThrottleLib.securelyHooked then
|
||||
print("ChatThrottleLib: Warning: There's an ANCIENT ChatThrottleLib.lua (pre-wow 2.0, <v16) in an addon somewhere. Get the addon updated or copy in a newer ChatThrottleLib.lua (>=v16) in it!")
|
||||
-- ATTEMPT to unhook; this'll behave badly if someone else has hooked...
|
||||
-- ... and if someone has securehooked, they can kiss that goodbye too... >.<
|
||||
_G.SendChatMessage = _G.ChatThrottleLib.ORIG_SendChatMessage
|
||||
if _G.ChatThrottleLib.ORIG_SendAddonMessage then
|
||||
_G.SendAddonMessage = _G.ChatThrottleLib.ORIG_SendAddonMessage
|
||||
end
|
||||
end
|
||||
_G.ChatThrottleLib.ORIG_SendChatMessage = nil
|
||||
_G.ChatThrottleLib.ORIG_SendAddonMessage = nil
|
||||
end
|
||||
|
||||
if not _G.ChatThrottleLib then
|
||||
_G.ChatThrottleLib = {}
|
||||
end
|
||||
|
||||
ChatThrottleLib = _G.ChatThrottleLib -- in case some addon does "local ChatThrottleLib" above us and we're copypasted (AceComm-2, sigh)
|
||||
local ChatThrottleLib = _G.ChatThrottleLib
|
||||
|
||||
ChatThrottleLib.version = CTL_VERSION
|
||||
|
||||
|
||||
|
||||
------------------ TWEAKABLES -----------------
|
||||
|
||||
ChatThrottleLib.MAX_CPS = 800 -- 2000 seems to be safe if NOTHING ELSE is happening. let's call it 800.
|
||||
ChatThrottleLib.MSG_OVERHEAD = 40 -- Guesstimate overhead for sending a message; source+dest+chattype+protocolstuff
|
||||
|
||||
ChatThrottleLib.BURST = 4000 -- WoW's server buffer seems to be about 32KB. 8KB should be safe, but seen disconnects on _some_ servers. Using 4KB now.
|
||||
|
||||
ChatThrottleLib.MIN_FPS = 20 -- Reduce output CPS to half (and don't burst) if FPS drops below this value
|
||||
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local table_remove = table.remove
|
||||
local tostring = tostring
|
||||
local GetTime = GetTime
|
||||
local math_min = math.min
|
||||
local math_max = math.max
|
||||
local next = next
|
||||
local strlen = string.len
|
||||
local GetFramerate = GetFramerate
|
||||
local strlower = string.lower
|
||||
local unpack,type,pairs,wipe = unpack,type,pairs,wipe
|
||||
local UnitInRaid,GetNumPartyMembers = UnitInRaid,GetNumPartyMembers
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Double-linked ring implementation
|
||||
|
||||
local Ring = {}
|
||||
local RingMeta = { __index = Ring }
|
||||
|
||||
function Ring:New()
|
||||
local ret = {}
|
||||
setmetatable(ret, RingMeta)
|
||||
return ret
|
||||
end
|
||||
|
||||
function Ring:Add(obj) -- Append at the "far end" of the ring (aka just before the current position)
|
||||
if self.pos then
|
||||
obj.prev = self.pos.prev
|
||||
obj.prev.next = obj
|
||||
obj.next = self.pos
|
||||
obj.next.prev = obj
|
||||
else
|
||||
obj.next = obj
|
||||
obj.prev = obj
|
||||
self.pos = obj
|
||||
end
|
||||
end
|
||||
|
||||
function Ring:Remove(obj)
|
||||
obj.next.prev = obj.prev
|
||||
obj.prev.next = obj.next
|
||||
if self.pos == obj then
|
||||
self.pos = obj.next
|
||||
if self.pos == obj then
|
||||
self.pos = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Recycling bin for pipes
|
||||
-- A pipe is a plain integer-indexed queue of messages
|
||||
-- Pipes normally live in Rings of pipes (3 rings total, one per priority)
|
||||
|
||||
ChatThrottleLib.PipeBin = nil -- pre-v19, drastically different
|
||||
local PipeBin = setmetatable({}, {__mode="k"})
|
||||
|
||||
local function DelPipe(pipe)
|
||||
PipeBin[pipe] = true
|
||||
end
|
||||
|
||||
local function NewPipe()
|
||||
local pipe = next(PipeBin)
|
||||
if pipe then
|
||||
wipe(pipe)
|
||||
PipeBin[pipe] = nil
|
||||
return pipe
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Recycling bin for messages
|
||||
|
||||
ChatThrottleLib.MsgBin = nil -- pre-v19, drastically different
|
||||
local MsgBin = setmetatable({}, {__mode="k"})
|
||||
|
||||
local function DelMsg(msg)
|
||||
msg[1] = nil
|
||||
-- there's more parameters, but they're very repetetive so the string pool doesn't suffer really, and it's faster to just not delete them.
|
||||
MsgBin[msg] = true
|
||||
end
|
||||
|
||||
local function NewMsg()
|
||||
local msg = next(MsgBin)
|
||||
if msg then
|
||||
MsgBin[msg] = nil
|
||||
return msg
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- ChatThrottleLib:Init
|
||||
-- Initialize queues, set up frame for OnUpdate, etc
|
||||
|
||||
|
||||
function ChatThrottleLib:Init()
|
||||
|
||||
-- Set up queues
|
||||
if not self.Prio then
|
||||
self.Prio = {}
|
||||
self.Prio["ALERT"] = { ByName = {}, Ring = Ring:New(), avail = 0 }
|
||||
self.Prio["NORMAL"] = { ByName = {}, Ring = Ring:New(), avail = 0 }
|
||||
self.Prio["BULK"] = { ByName = {}, Ring = Ring:New(), avail = 0 }
|
||||
end
|
||||
|
||||
-- v4: total send counters per priority
|
||||
for _, Prio in pairs(self.Prio) do
|
||||
Prio.nTotalSent = Prio.nTotalSent or 0
|
||||
end
|
||||
|
||||
if not self.avail then
|
||||
self.avail = 0 -- v5
|
||||
end
|
||||
if not self.nTotalSent then
|
||||
self.nTotalSent = 0 -- v5
|
||||
end
|
||||
|
||||
|
||||
-- Set up a frame to get OnUpdate events
|
||||
if not self.Frame then
|
||||
self.Frame = CreateFrame("Frame")
|
||||
self.Frame:Hide()
|
||||
end
|
||||
self.Frame:SetScript("OnUpdate", self.OnUpdate)
|
||||
self.Frame:SetScript("OnEvent", self.OnEvent) -- v11: Monitor P_E_W so we can throttle hard for a few seconds
|
||||
self.Frame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
self.OnUpdateDelay = 0
|
||||
self.LastAvailUpdate = GetTime()
|
||||
self.HardThrottlingBeginTime = GetTime() -- v11: Throttle hard for a few seconds after startup
|
||||
|
||||
-- Hook SendChatMessage and SendAddonMessage so we can measure unpiped traffic and avoid overloads (v7)
|
||||
if not self.securelyHooked then
|
||||
-- Use secure hooks as of v16. Old regular hook support yanked out in v21.
|
||||
self.securelyHooked = true
|
||||
--SendChatMessage
|
||||
hooksecurefunc("SendChatMessage", function(...)
|
||||
return ChatThrottleLib.Hook_SendChatMessage(...)
|
||||
end)
|
||||
--SendAddonMessage
|
||||
hooksecurefunc("SendAddonMessage", function(...)
|
||||
return ChatThrottleLib.Hook_SendAddonMessage(...)
|
||||
end)
|
||||
end
|
||||
self.nBypass = 0
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- ChatThrottleLib.Hook_SendChatMessage / .Hook_SendAddonMessage
|
||||
|
||||
local bMyTraffic = false
|
||||
|
||||
function ChatThrottleLib.Hook_SendChatMessage(text, chattype, language, destination, ...)
|
||||
if bMyTraffic then
|
||||
return
|
||||
end
|
||||
local self = ChatThrottleLib
|
||||
local size = strlen(tostring(text or "")) + strlen(tostring(destination or "")) + self.MSG_OVERHEAD
|
||||
self.avail = self.avail - size
|
||||
self.nBypass = self.nBypass + size -- just a statistic
|
||||
end
|
||||
function ChatThrottleLib.Hook_SendAddonMessage(prefix, text, chattype, destination, ...)
|
||||
if bMyTraffic then
|
||||
return
|
||||
end
|
||||
local self = ChatThrottleLib
|
||||
local size = tostring(text or ""):len() + tostring(prefix or ""):len();
|
||||
size = size + tostring(destination or ""):len() + self.MSG_OVERHEAD
|
||||
self.avail = self.avail - size
|
||||
self.nBypass = self.nBypass + size -- just a statistic
|
||||
end
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- ChatThrottleLib:UpdateAvail
|
||||
-- Update self.avail with how much bandwidth is currently available
|
||||
|
||||
function ChatThrottleLib:UpdateAvail()
|
||||
local now = GetTime()
|
||||
local MAX_CPS = self.MAX_CPS;
|
||||
local newavail = MAX_CPS * (now - self.LastAvailUpdate)
|
||||
local avail = self.avail
|
||||
|
||||
if now - self.HardThrottlingBeginTime < 5 then
|
||||
-- First 5 seconds after startup/zoning: VERY hard clamping to avoid irritating the server rate limiter, it seems very cranky then
|
||||
avail = math_min(avail + (newavail*0.1), MAX_CPS*0.5)
|
||||
self.bChoking = true
|
||||
elseif GetFramerate() < self.MIN_FPS then -- GetFramerate call takes ~0.002 secs
|
||||
avail = math_min(MAX_CPS, avail + newavail*0.5)
|
||||
self.bChoking = true -- just a statistic
|
||||
else
|
||||
avail = math_min(self.BURST, avail + newavail)
|
||||
self.bChoking = false
|
||||
end
|
||||
|
||||
avail = math_max(avail, 0-(MAX_CPS*2)) -- Can go negative when someone is eating bandwidth past the lib. but we refuse to stay silent for more than 2 seconds; if they can do it, we can.
|
||||
|
||||
self.avail = avail
|
||||
self.LastAvailUpdate = now
|
||||
|
||||
return avail
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Despooling logic
|
||||
-- Reminder:
|
||||
-- - We have 3 Priorities, each containing a "Ring" construct ...
|
||||
-- - ... made up of N "Pipe"s (1 for each destination/pipename)
|
||||
-- - and each pipe contains messages
|
||||
|
||||
function ChatThrottleLib:Despool(Prio)
|
||||
local ring = Prio.Ring
|
||||
while ring.pos and Prio.avail > ring.pos[1].nSize do
|
||||
local msg = table_remove(ring.pos, 1)
|
||||
if not ring.pos[1] then -- did we remove last msg in this pipe?
|
||||
local pipe = Prio.Ring.pos
|
||||
Prio.Ring:Remove(pipe)
|
||||
Prio.ByName[pipe.name] = nil
|
||||
DelPipe(pipe)
|
||||
else
|
||||
Prio.Ring.pos = Prio.Ring.pos.next
|
||||
end
|
||||
local didSend=false
|
||||
local lowerDest = strlower(msg[3] or "")
|
||||
if lowerDest == "raid" and not UnitInRaid("player") then
|
||||
-- do nothing
|
||||
elseif lowerDest == "party" and GetNumPartyMembers() == 0 then
|
||||
-- do nothing
|
||||
else
|
||||
Prio.avail = Prio.avail - msg.nSize
|
||||
bMyTraffic = true
|
||||
msg.f(unpack(msg, 1, msg.n))
|
||||
bMyTraffic = false
|
||||
Prio.nTotalSent = Prio.nTotalSent + msg.nSize
|
||||
DelMsg(msg)
|
||||
didSend = true
|
||||
end
|
||||
-- notify caller of delivery (even if we didn't send it)
|
||||
if msg.callbackFn then
|
||||
msg.callbackFn (msg.callbackArg, didSend)
|
||||
end
|
||||
-- USER CALLBACK MAY ERROR
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ChatThrottleLib.OnEvent(this,event)
|
||||
-- v11: We know that the rate limiter is touchy after login. Assume that it's touchy after zoning, too.
|
||||
local self = ChatThrottleLib
|
||||
if event == "PLAYER_ENTERING_WORLD" then
|
||||
self.HardThrottlingBeginTime = GetTime() -- Throttle hard for a few seconds after zoning
|
||||
self.avail = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ChatThrottleLib.OnUpdate(this,delay)
|
||||
local self = ChatThrottleLib
|
||||
|
||||
self.OnUpdateDelay = self.OnUpdateDelay + delay
|
||||
if self.OnUpdateDelay < 0.08 then
|
||||
return
|
||||
end
|
||||
self.OnUpdateDelay = 0
|
||||
|
||||
self:UpdateAvail()
|
||||
|
||||
if self.avail < 0 then
|
||||
return -- argh. some bastard is spewing stuff past the lib. just bail early to save cpu.
|
||||
end
|
||||
|
||||
-- See how many of our priorities have queued messages (we only have 3, don't worry about the loop)
|
||||
local n = 0
|
||||
for prioname,Prio in pairs(self.Prio) do
|
||||
if Prio.Ring.pos or Prio.avail < 0 then
|
||||
n = n + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Anything queued still?
|
||||
if n<1 then
|
||||
-- Nope. Move spillover bandwidth to global availability gauge and clear self.bQueueing
|
||||
for prioname, Prio in pairs(self.Prio) do
|
||||
self.avail = self.avail + Prio.avail
|
||||
Prio.avail = 0
|
||||
end
|
||||
self.bQueueing = false
|
||||
self.Frame:Hide()
|
||||
return
|
||||
end
|
||||
|
||||
-- There's stuff queued. Hand out available bandwidth to priorities as needed and despool their queues
|
||||
local avail = self.avail/n
|
||||
self.avail = 0
|
||||
|
||||
for prioname, Prio in pairs(self.Prio) do
|
||||
if Prio.Ring.pos or Prio.avail < 0 then
|
||||
Prio.avail = Prio.avail + avail
|
||||
if Prio.Ring.pos and Prio.avail > Prio.Ring.pos[1].nSize then
|
||||
self:Despool(Prio)
|
||||
-- Note: We might not get here if the user-supplied callback function errors out! Take care!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Spooling logic
|
||||
|
||||
function ChatThrottleLib:Enqueue(prioname, pipename, msg)
|
||||
local Prio = self.Prio[prioname]
|
||||
local pipe = Prio.ByName[pipename]
|
||||
if not pipe then
|
||||
self.Frame:Show()
|
||||
pipe = NewPipe()
|
||||
pipe.name = pipename
|
||||
Prio.ByName[pipename] = pipe
|
||||
Prio.Ring:Add(pipe)
|
||||
end
|
||||
|
||||
pipe[#pipe + 1] = msg
|
||||
|
||||
self.bQueueing = true
|
||||
end
|
||||
|
||||
function ChatThrottleLib:SendChatMessage(prio, prefix, text, chattype, language, destination, queueName, callbackFn, callbackArg)
|
||||
if not self or not prio or not prefix or not text or not self.Prio[prio] then
|
||||
error('Usage: ChatThrottleLib:SendChatMessage("{BULK||NORMAL||ALERT}", "prefix", "text"[, "chattype"[, "language"[, "destination"]]]', 2)
|
||||
end
|
||||
if callbackFn and type(callbackFn)~="function" then
|
||||
error('ChatThrottleLib:ChatMessage(): callbackFn: expected function, got '..type(callbackFn), 2)
|
||||
end
|
||||
|
||||
local nSize = text:len()
|
||||
|
||||
if nSize>255 then
|
||||
error("ChatThrottleLib:SendChatMessage(): message length cannot exceed 255 bytes", 2)
|
||||
end
|
||||
|
||||
nSize = nSize + self.MSG_OVERHEAD
|
||||
|
||||
-- Check if there's room in the global available bandwidth gauge to send directly
|
||||
if not self.bQueueing and nSize < self:UpdateAvail() then
|
||||
self.avail = self.avail - nSize
|
||||
bMyTraffic = true
|
||||
_G.SendChatMessage(text, chattype, language, destination)
|
||||
bMyTraffic = false
|
||||
self.Prio[prio].nTotalSent = self.Prio[prio].nTotalSent + nSize
|
||||
if callbackFn then
|
||||
callbackFn (callbackArg, true)
|
||||
end
|
||||
-- USER CALLBACK MAY ERROR
|
||||
return
|
||||
end
|
||||
|
||||
-- Message needs to be queued
|
||||
local msg = NewMsg()
|
||||
msg.f = _G.SendChatMessage
|
||||
msg[1] = text
|
||||
msg[2] = chattype or "SAY"
|
||||
msg[3] = language
|
||||
msg[4] = destination
|
||||
msg.n = 4
|
||||
msg.nSize = nSize
|
||||
msg.callbackFn = callbackFn
|
||||
msg.callbackArg = callbackArg
|
||||
|
||||
self:Enqueue(prio, queueName or (prefix..(chattype or "SAY")..(destination or "")), msg)
|
||||
end
|
||||
|
||||
|
||||
function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target, queueName, callbackFn, callbackArg)
|
||||
if not self or not prio or not prefix or not text or not chattype or not self.Prio[prio] then
|
||||
error('Usage: ChatThrottleLib:SendAddonMessage("{BULK||NORMAL||ALERT}", "prefix", "text", "chattype"[, "target"])', 2)
|
||||
end
|
||||
if callbackFn and type(callbackFn)~="function" then
|
||||
error('ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got '..type(callbackFn), 2)
|
||||
end
|
||||
|
||||
local nSize = prefix:len() + 1 + text:len();
|
||||
|
||||
if nSize>255 then
|
||||
error("ChatThrottleLib:SendAddonMessage(): prefix + message length cannot exceed 254 bytes", 2)
|
||||
end
|
||||
|
||||
nSize = nSize + self.MSG_OVERHEAD;
|
||||
|
||||
-- Check if there's room in the global available bandwidth gauge to send directly
|
||||
if not self.bQueueing and nSize < self:UpdateAvail() then
|
||||
self.avail = self.avail - nSize
|
||||
bMyTraffic = true
|
||||
_G.SendAddonMessage(prefix, text, chattype, target)
|
||||
bMyTraffic = false
|
||||
self.Prio[prio].nTotalSent = self.Prio[prio].nTotalSent + nSize
|
||||
if callbackFn then
|
||||
callbackFn (callbackArg, true)
|
||||
end
|
||||
-- USER CALLBACK MAY ERROR
|
||||
return
|
||||
end
|
||||
|
||||
-- Message needs to be queued
|
||||
local msg = NewMsg()
|
||||
msg.f = _G.SendAddonMessage
|
||||
msg[1] = prefix
|
||||
msg[2] = text
|
||||
msg[3] = chattype
|
||||
msg[4] = target
|
||||
msg.n = (target~=nil) and 4 or 3;
|
||||
msg.nSize = nSize
|
||||
msg.callbackFn = callbackFn
|
||||
msg.callbackArg = callbackArg
|
||||
|
||||
self:Enqueue(prio, queueName or (prefix..chattype..(target or "")), msg)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Get the ball rolling!
|
||||
|
||||
ChatThrottleLib:Init()
|
||||
|
||||
--[[ WoWBench debugging snippet
|
||||
if(WOWB_VER) then
|
||||
local function SayTimer()
|
||||
print("SAY: "..GetTime().." "..arg1)
|
||||
end
|
||||
ChatThrottleLib.Frame:SetScript("OnEvent", SayTimer)
|
||||
ChatThrottleLib.Frame:RegisterEvent("CHAT_MSG_SAY")
|
||||
end
|
||||
]]
|
||||
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
--- **AceConsole-3.0** provides registration facilities for slash commands.
|
||||
-- You can register slash commands to your custom functions and use the `GetArgs` function to parse them
|
||||
-- to your addons individual needs.
|
||||
--
|
||||
-- **AceConsole-3.0** can be embeded into your addon, either explicitly by calling AceConsole:Embed(MyAddon) or by
|
||||
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
|
||||
-- and can be accessed directly, without having to explicitly call AceConsole itself.\\
|
||||
-- It is recommended to embed AceConsole, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceConsole.
|
||||
-- @class file
|
||||
-- @name AceConsole-3.0
|
||||
-- @release $Id$
|
||||
local MAJOR,MINOR = "AceConsole-3.0", 7
|
||||
|
||||
local AceConsole, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceConsole then return end -- No upgrade needed
|
||||
|
||||
AceConsole.embeds = AceConsole.embeds or {} -- table containing objects AceConsole is embedded in.
|
||||
AceConsole.commands = AceConsole.commands or {} -- table containing commands registered
|
||||
AceConsole.weakcommands = AceConsole.weakcommands or {} -- table containing self, command => func references for weak commands that don't persist through enable/disable
|
||||
|
||||
-- Lua APIs
|
||||
local tconcat, tostring, select = table.concat, tostring, select
|
||||
local type, pairs, error = type, pairs, error
|
||||
local format, strfind, strsub = string.format, string.find, string.sub
|
||||
local max = math.max
|
||||
|
||||
-- WoW APIs
|
||||
local _G = _G
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: DEFAULT_CHAT_FRAME, SlashCmdList, hash_SlashCmdList
|
||||
|
||||
local tmp={}
|
||||
local function Print(self,frame,...)
|
||||
local n=0
|
||||
if self ~= AceConsole then
|
||||
n=n+1
|
||||
tmp[n] = "|cff33ff99"..tostring( self ).."|r:"
|
||||
end
|
||||
for i=1, select("#", ...) do
|
||||
n=n+1
|
||||
tmp[n] = tostring(select(i, ...))
|
||||
end
|
||||
frame:AddMessage( tconcat(tmp," ",1,n) )
|
||||
end
|
||||
|
||||
--- Print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function)
|
||||
-- @paramsig [chatframe ,] ...
|
||||
-- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function)
|
||||
-- @param ... List of any values to be printed
|
||||
function AceConsole:Print(...)
|
||||
local frame = ...
|
||||
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member?
|
||||
return Print(self, frame, select(2,...))
|
||||
else
|
||||
return Print(self, DEFAULT_CHAT_FRAME, ...)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Formatted (using format()) print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function)
|
||||
-- @paramsig [chatframe ,] "format"[, ...]
|
||||
-- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function)
|
||||
-- @param format Format string - same syntax as standard Lua format()
|
||||
-- @param ... Arguments to the format string
|
||||
function AceConsole:Printf(...)
|
||||
local frame = ...
|
||||
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member?
|
||||
return Print(self, frame, format(select(2,...)))
|
||||
else
|
||||
return Print(self, DEFAULT_CHAT_FRAME, format(...))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Register a simple chat command
|
||||
-- @param command Chat command to be registered WITHOUT leading "/"
|
||||
-- @param func Function to call when the slash command is being used (funcref or methodname)
|
||||
-- @param persist if false, the command will be soft disabled/enabled when aceconsole is used as a mixin (default: true)
|
||||
function AceConsole:RegisterChatCommand( command, func, persist )
|
||||
if type(command)~="string" then error([[Usage: AceConsole:RegisterChatCommand( "command", func[, persist ]): 'command' - expected a string]], 2) end
|
||||
|
||||
if persist==nil then persist=true end -- I'd rather have my addon's "/addon enable" around if the author screws up. Having some extra slash regged when it shouldnt be isn't as destructive. True is a better default. /Mikk
|
||||
|
||||
local name = "ACECONSOLE_"..command:upper()
|
||||
|
||||
if type( func ) == "string" then
|
||||
SlashCmdList[name] = function(input, editBox)
|
||||
self[func](self, input, editBox)
|
||||
end
|
||||
else
|
||||
SlashCmdList[name] = func
|
||||
end
|
||||
_G["SLASH_"..name.."1"] = "/"..command:lower()
|
||||
AceConsole.commands[command] = name
|
||||
-- non-persisting commands are registered for enabling disabling
|
||||
if not persist then
|
||||
if not AceConsole.weakcommands[self] then AceConsole.weakcommands[self] = {} end
|
||||
AceConsole.weakcommands[self][command] = func
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--- Unregister a chatcommand
|
||||
-- @param command Chat command to be unregistered WITHOUT leading "/"
|
||||
function AceConsole:UnregisterChatCommand( command )
|
||||
local name = AceConsole.commands[command]
|
||||
if name then
|
||||
SlashCmdList[name] = nil
|
||||
_G["SLASH_" .. name .. "1"] = nil
|
||||
hash_SlashCmdList["/" .. command:upper()] = nil
|
||||
AceConsole.commands[command] = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- Get an iterator over all Chat Commands registered with AceConsole
|
||||
-- @return Iterator (pairs) over all commands
|
||||
function AceConsole:IterateChatCommands() return pairs(AceConsole.commands) end
|
||||
|
||||
|
||||
local function nils(n, ...)
|
||||
if n>1 then
|
||||
return nil, nils(n-1, ...)
|
||||
elseif n==1 then
|
||||
return nil, ...
|
||||
else
|
||||
return ...
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Retreive one or more space-separated arguments from a string.
|
||||
-- Treats quoted strings and itemlinks as non-spaced.
|
||||
-- @param str The raw argument string
|
||||
-- @param numargs How many arguments to get (default 1)
|
||||
-- @param startpos Where in the string to start scanning (default 1)
|
||||
-- @return Returns arg1, arg2, ..., nextposition\\
|
||||
-- Missing arguments will be returned as nils. 'nextposition' is returned as 1e9 at the end of the string.
|
||||
function AceConsole:GetArgs(str, numargs, startpos)
|
||||
numargs = numargs or 1
|
||||
startpos = max(startpos or 1, 1)
|
||||
|
||||
local pos=startpos
|
||||
|
||||
-- find start of new arg
|
||||
pos = strfind(str, "[^ ]", pos)
|
||||
if not pos then -- whoops, end of string
|
||||
return nils(numargs, 1e9)
|
||||
end
|
||||
|
||||
if numargs<1 then
|
||||
return pos
|
||||
end
|
||||
|
||||
-- quoted or space separated? find out which pattern to use
|
||||
local delim_or_pipe
|
||||
local ch = strsub(str, pos, pos)
|
||||
if ch=='"' then
|
||||
pos = pos + 1
|
||||
delim_or_pipe='([|"])'
|
||||
elseif ch=="'" then
|
||||
pos = pos + 1
|
||||
delim_or_pipe="([|'])"
|
||||
else
|
||||
delim_or_pipe="([| ])"
|
||||
end
|
||||
|
||||
startpos = pos
|
||||
|
||||
while true do
|
||||
-- find delimiter or hyperlink
|
||||
local ch,_
|
||||
pos,_,ch = strfind(str, delim_or_pipe, pos)
|
||||
|
||||
if not pos then break end
|
||||
|
||||
if ch=="|" then
|
||||
-- some kind of escape
|
||||
|
||||
if strsub(str,pos,pos+1)=="|H" then
|
||||
-- It's a |H....|hhyper link!|h
|
||||
pos=strfind(str, "|h", pos+2) -- first |h
|
||||
if not pos then break end
|
||||
|
||||
pos=strfind(str, "|h", pos+2) -- second |h
|
||||
if not pos then break end
|
||||
elseif strsub(str,pos, pos+1) == "|T" then
|
||||
-- It's a |T....|t texture
|
||||
pos=strfind(str, "|t", pos+2)
|
||||
if not pos then break end
|
||||
end
|
||||
|
||||
pos=pos+2 -- skip past this escape (last |h if it was a hyperlink)
|
||||
|
||||
else
|
||||
-- found delimiter, done with this arg
|
||||
return strsub(str, startpos, pos-1), AceConsole:GetArgs(str, numargs-1, pos+1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- search aborted, we hit end of string. return it all as one argument. (yes, even if it's an unterminated quote or hyperlink)
|
||||
return strsub(str, startpos), nils(numargs-1, 1e9)
|
||||
end
|
||||
|
||||
|
||||
--- embedding and embed handling
|
||||
|
||||
local mixins = {
|
||||
"Print",
|
||||
"Printf",
|
||||
"RegisterChatCommand",
|
||||
"UnregisterChatCommand",
|
||||
"GetArgs",
|
||||
}
|
||||
|
||||
-- Embeds AceConsole into the target object making the functions from the mixins list available on target:..
|
||||
-- @param target target object to embed AceBucket in
|
||||
function AceConsole:Embed( target )
|
||||
for k, v in pairs( mixins ) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeds[target] = true
|
||||
return target
|
||||
end
|
||||
|
||||
function AceConsole:OnEmbedEnable( target )
|
||||
if AceConsole.weakcommands[target] then
|
||||
for command, func in pairs( AceConsole.weakcommands[target] ) do
|
||||
target:RegisterChatCommand( command, func, false, true ) -- nonpersisting and silent registry
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AceConsole:OnEmbedDisable( target )
|
||||
if AceConsole.weakcommands[target] then
|
||||
for command, func in pairs( AceConsole.weakcommands[target] ) do
|
||||
target:UnregisterChatCommand( command ) -- TODO: this could potentially unregister a command from another application in case of command conflicts. Do we care?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for addon in pairs(AceConsole.embeds) do
|
||||
AceConsole:Embed(addon)
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="AceConsole-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,741 @@
|
||||
--- **AceDB-3.0** manages the SavedVariables of your addon.
|
||||
-- It offers profile management, smart defaults and namespaces for modules.\\
|
||||
-- Data can be saved in different data-types, depending on its intended usage.
|
||||
-- The most common data-type is the `profile` type, which allows the user to choose
|
||||
-- the active profile, and manage the profiles of all of his characters.\\
|
||||
-- The following data types are available:
|
||||
-- * **char** Character-specific data. Every character has its own database.
|
||||
-- * **realm** Realm-specific data. All of the players characters on the same realm share this database.
|
||||
-- * **class** Class-specific data. All of the players characters of the same class share this database.
|
||||
-- * **race** Race-specific data. All of the players characters of the same race share this database.
|
||||
-- * **faction** Faction-specific data. All of the players characters of the same faction share this database.
|
||||
-- * **factionrealm** Faction and realm specific data. All of the players characters on the same realm and of the same faction share this database.
|
||||
-- * **locale** Locale specific data, based on the locale of the players game client.
|
||||
-- * **global** Global Data. All characters on the same account share this database.
|
||||
-- * **profile** Profile-specific data. All characters using the same profile share this database. The user can control which profile should be used.
|
||||
--
|
||||
-- Creating a new Database using the `:New` function will return a new DBObject. A database will inherit all functions
|
||||
-- of the DBObjectLib listed here. \\
|
||||
-- If you create a new namespaced child-database (`:RegisterNamespace`), you'll get a DBObject as well, but note
|
||||
-- that the child-databases cannot individually change their profile, and are linked to their parents profile - and because of that,
|
||||
-- the profile related APIs are not available. Only `:RegisterDefaults` and `:ResetProfile` are available on child-databases.
|
||||
--
|
||||
-- For more details on how to use AceDB-3.0, see the [[AceDB-3.0 Tutorial]].
|
||||
--
|
||||
-- You may also be interested in [[libdualspec-1-0|LibDualSpec-1.0]] to do profile switching automatically when switching specs.
|
||||
--
|
||||
-- @usage
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("DBExample")
|
||||
--
|
||||
-- -- declare defaults to be used in the DB
|
||||
-- local defaults = {
|
||||
-- profile = {
|
||||
-- setting = true,
|
||||
-- }
|
||||
-- }
|
||||
--
|
||||
-- function MyAddon:OnInitialize()
|
||||
-- -- Assuming the .toc says ## SavedVariables: MyAddonDB
|
||||
-- self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
|
||||
-- end
|
||||
-- @class file
|
||||
-- @name AceDB-3.0.lua
|
||||
-- @release $Id$
|
||||
local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 27
|
||||
local AceDB = LibStub:NewLibrary(ACEDB_MAJOR, ACEDB_MINOR)
|
||||
|
||||
if not AceDB then return end -- No upgrade needed
|
||||
|
||||
-- Lua APIs
|
||||
local type, pairs, next, error = type, pairs, next, error
|
||||
local setmetatable, rawset, rawget = setmetatable, rawset, rawget
|
||||
|
||||
-- WoW APIs
|
||||
local _G = _G
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: LibStub
|
||||
|
||||
AceDB.db_registry = AceDB.db_registry or {}
|
||||
AceDB.frame = AceDB.frame or CreateFrame("Frame")
|
||||
|
||||
local CallbackHandler
|
||||
local CallbackDummy = { Fire = function() end }
|
||||
|
||||
local DBObjectLib = {}
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
AceDB Utility Functions
|
||||
---------------------------------------------------------------------------]]
|
||||
|
||||
-- Simple shallow copy for copying defaults
|
||||
local function copyTable(src, dest)
|
||||
if type(dest) ~= "table" then dest = {} end
|
||||
if type(src) == "table" then
|
||||
for k,v in pairs(src) do
|
||||
if type(v) == "table" then
|
||||
-- try to index the key first so that the metatable creates the defaults, if set, and use that table
|
||||
v = copyTable(v, dest[k])
|
||||
end
|
||||
dest[k] = v
|
||||
end
|
||||
end
|
||||
return dest
|
||||
end
|
||||
|
||||
-- Called to add defaults to a section of the database
|
||||
--
|
||||
-- When a ["*"] default section is indexed with a new key, a table is returned
|
||||
-- and set in the host table. These tables must be cleaned up by removeDefaults
|
||||
-- in order to ensure we don't write empty default tables.
|
||||
local function copyDefaults(dest, src)
|
||||
-- this happens if some value in the SV overwrites our default value with a non-table
|
||||
--if type(dest) ~= "table" then return end
|
||||
for k, v in pairs(src) do
|
||||
if k == "*" or k == "**" then
|
||||
if type(v) == "table" then
|
||||
-- This is a metatable used for table defaults
|
||||
local mt = {
|
||||
-- This handles the lookup and creation of new subtables
|
||||
__index = function(t,k)
|
||||
if k == nil then return nil end
|
||||
local tbl = {}
|
||||
copyDefaults(tbl, v)
|
||||
rawset(t, k, tbl)
|
||||
return tbl
|
||||
end,
|
||||
}
|
||||
setmetatable(dest, mt)
|
||||
-- handle already existing tables in the SV
|
||||
for dk, dv in pairs(dest) do
|
||||
if not rawget(src, dk) and type(dv) == "table" then
|
||||
copyDefaults(dv, v)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Values are not tables, so this is just a simple return
|
||||
local mt = {__index = function(t,k) return k~=nil and v or nil end}
|
||||
setmetatable(dest, mt)
|
||||
end
|
||||
elseif type(v) == "table" then
|
||||
if not rawget(dest, k) then rawset(dest, k, {}) end
|
||||
if type(dest[k]) == "table" then
|
||||
copyDefaults(dest[k], v)
|
||||
if src['**'] then
|
||||
copyDefaults(dest[k], src['**'])
|
||||
end
|
||||
end
|
||||
else
|
||||
if rawget(dest, k) == nil then
|
||||
rawset(dest, k, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Called to remove all defaults in the default table from the database
|
||||
local function removeDefaults(db, defaults, blocker)
|
||||
-- remove all metatables from the db, so we don't accidentally create new sub-tables through them
|
||||
setmetatable(db, nil)
|
||||
-- loop through the defaults and remove their content
|
||||
for k,v in pairs(defaults) do
|
||||
if k == "*" or k == "**" then
|
||||
if type(v) == "table" then
|
||||
-- Loop through all the actual k,v pairs and remove
|
||||
for key, value in pairs(db) do
|
||||
if type(value) == "table" then
|
||||
-- if the key was not explicitly specified in the defaults table, just strip everything from * and ** tables
|
||||
if defaults[key] == nil and (not blocker or blocker[key] == nil) then
|
||||
removeDefaults(value, v)
|
||||
-- if the table is empty afterwards, remove it
|
||||
if next(value) == nil then
|
||||
db[key] = nil
|
||||
end
|
||||
-- if it was specified, only strip ** content, but block values which were set in the key table
|
||||
elseif k == "**" then
|
||||
removeDefaults(value, v, defaults[key])
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif k == "*" then
|
||||
-- check for non-table default
|
||||
for key, value in pairs(db) do
|
||||
if defaults[key] == nil and v == value then
|
||||
db[key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif type(v) == "table" and type(db[k]) == "table" then
|
||||
-- if a blocker was set, dive into it, to allow multi-level defaults
|
||||
removeDefaults(db[k], v, blocker and blocker[k])
|
||||
if next(db[k]) == nil then
|
||||
db[k] = nil
|
||||
end
|
||||
else
|
||||
-- check if the current value matches the default, and that its not blocked by another defaults table
|
||||
if db[k] == defaults[k] and (not blocker or blocker[k] == nil) then
|
||||
db[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- This is called when a table section is first accessed, to set up the defaults
|
||||
local function initSection(db, section, svstore, key, defaults)
|
||||
local sv = rawget(db, "sv")
|
||||
|
||||
local tableCreated
|
||||
if not sv[svstore] then sv[svstore] = {} end
|
||||
if not sv[svstore][key] then
|
||||
sv[svstore][key] = {}
|
||||
tableCreated = true
|
||||
end
|
||||
|
||||
local tbl = sv[svstore][key]
|
||||
|
||||
if defaults then
|
||||
copyDefaults(tbl, defaults)
|
||||
end
|
||||
rawset(db, section, tbl)
|
||||
|
||||
return tableCreated, tbl
|
||||
end
|
||||
|
||||
-- Metatable to handle the dynamic creation of sections and copying of sections.
|
||||
local dbmt = {
|
||||
__index = function(t, section)
|
||||
local keys = rawget(t, "keys")
|
||||
local key = keys[section]
|
||||
if key then
|
||||
local defaultTbl = rawget(t, "defaults")
|
||||
local defaults = defaultTbl and defaultTbl[section]
|
||||
|
||||
if section == "profile" then
|
||||
local new = initSection(t, section, "profiles", key, defaults)
|
||||
if new then
|
||||
-- Callback: OnNewProfile, database, newProfileKey
|
||||
t.callbacks:Fire("OnNewProfile", t, key)
|
||||
end
|
||||
elseif section == "profiles" then
|
||||
local sv = rawget(t, "sv")
|
||||
if not sv.profiles then sv.profiles = {} end
|
||||
rawset(t, "profiles", sv.profiles)
|
||||
elseif section == "global" then
|
||||
local sv = rawget(t, "sv")
|
||||
if not sv.global then sv.global = {} end
|
||||
if defaults then
|
||||
copyDefaults(sv.global, defaults)
|
||||
end
|
||||
rawset(t, section, sv.global)
|
||||
else
|
||||
initSection(t, section, section, key, defaults)
|
||||
end
|
||||
end
|
||||
|
||||
return rawget(t, section)
|
||||
end
|
||||
}
|
||||
|
||||
local function validateDefaults(defaults, keyTbl, offset)
|
||||
if not defaults then return end
|
||||
offset = offset or 0
|
||||
for k in pairs(defaults) do
|
||||
if not keyTbl[k] or k == "profiles" then
|
||||
error(("Usage: AceDBObject:RegisterDefaults(defaults): '%s' is not a valid datatype."):format(k), 3 + offset)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local preserve_keys = {
|
||||
["callbacks"] = true,
|
||||
["RegisterCallback"] = true,
|
||||
["UnregisterCallback"] = true,
|
||||
["UnregisterAllCallbacks"] = true,
|
||||
["children"] = true,
|
||||
}
|
||||
|
||||
local realmKey = GetRealmName()
|
||||
local charKey = UnitName("player") .. " - " .. realmKey
|
||||
local _, classKey = UnitClass("player")
|
||||
local _, raceKey = UnitRace("player")
|
||||
local factionKey = UnitFactionGroup("player")
|
||||
local factionrealmKey = factionKey .. " - " .. realmKey
|
||||
local factionrealmregionKey = factionrealmKey .. " - " .. string.sub(GetCVar("realmList"), 1, 2):upper()
|
||||
local localeKey = GetLocale():lower()
|
||||
|
||||
-- Actual database initialization function
|
||||
local function initdb(sv, defaults, defaultProfile, olddb, parent)
|
||||
-- Generate the database keys for each section
|
||||
|
||||
-- map "true" to our "Default" profile
|
||||
if defaultProfile == true then defaultProfile = "Default" end
|
||||
|
||||
local profileKey
|
||||
if not parent then
|
||||
-- Make a container for profile keys
|
||||
if not sv.profileKeys then sv.profileKeys = {} end
|
||||
|
||||
-- Try to get the profile selected from the char db
|
||||
profileKey = sv.profileKeys[charKey] or defaultProfile or charKey
|
||||
|
||||
-- save the selected profile for later
|
||||
sv.profileKeys[charKey] = profileKey
|
||||
else
|
||||
-- Use the profile of the parents DB
|
||||
profileKey = parent.keys.profile or defaultProfile or charKey
|
||||
|
||||
-- clear the profileKeys in the DB, namespaces don't need to store them
|
||||
sv.profileKeys = nil
|
||||
end
|
||||
|
||||
-- This table contains keys that enable the dynamic creation
|
||||
-- of each section of the table. The 'global' and 'profiles'
|
||||
-- have a key of true, since they are handled in a special case
|
||||
local keyTbl= {
|
||||
["char"] = charKey,
|
||||
["realm"] = realmKey,
|
||||
["class"] = classKey,
|
||||
["race"] = raceKey,
|
||||
["faction"] = factionKey,
|
||||
["factionrealm"] = factionrealmKey,
|
||||
["factionrealmregion"] = factionrealmregionKey,
|
||||
["profile"] = profileKey,
|
||||
["locale"] = localeKey,
|
||||
["global"] = true,
|
||||
["profiles"] = true,
|
||||
}
|
||||
|
||||
validateDefaults(defaults, keyTbl, 1)
|
||||
|
||||
-- This allows us to use this function to reset an entire database
|
||||
-- Clear out the old database
|
||||
if olddb then
|
||||
for k,v in pairs(olddb) do if not preserve_keys[k] then olddb[k] = nil end end
|
||||
end
|
||||
|
||||
-- Give this database the metatable so it initializes dynamically
|
||||
local db = setmetatable(olddb or {}, dbmt)
|
||||
|
||||
if not rawget(db, "callbacks") then
|
||||
-- try to load CallbackHandler-1.0 if it loaded after our library
|
||||
if not CallbackHandler then CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0", true) end
|
||||
db.callbacks = CallbackHandler and CallbackHandler:New(db) or CallbackDummy
|
||||
end
|
||||
|
||||
-- Copy methods locally into the database object, to avoid hitting
|
||||
-- the metatable when calling methods
|
||||
|
||||
if not parent then
|
||||
for name, func in pairs(DBObjectLib) do
|
||||
db[name] = func
|
||||
end
|
||||
else
|
||||
-- hack this one in
|
||||
db.RegisterDefaults = DBObjectLib.RegisterDefaults
|
||||
db.ResetProfile = DBObjectLib.ResetProfile
|
||||
end
|
||||
|
||||
-- Set some properties in the database object
|
||||
db.profiles = sv.profiles
|
||||
db.keys = keyTbl
|
||||
db.sv = sv
|
||||
--db.sv_name = name
|
||||
db.defaults = defaults
|
||||
db.parent = parent
|
||||
|
||||
-- store the DB in the registry
|
||||
AceDB.db_registry[db] = true
|
||||
|
||||
return db
|
||||
end
|
||||
|
||||
-- handle PLAYER_LOGOUT
|
||||
-- strip all defaults from all databases
|
||||
-- and cleans up empty sections
|
||||
local function logoutHandler(frame, event)
|
||||
if event == "PLAYER_LOGOUT" then
|
||||
for db in pairs(AceDB.db_registry) do
|
||||
db.callbacks:Fire("OnDatabaseShutdown", db)
|
||||
db:RegisterDefaults(nil)
|
||||
|
||||
-- cleanup sections that are empty without defaults
|
||||
local sv = rawget(db, "sv")
|
||||
for section in pairs(db.keys) do
|
||||
if rawget(sv, section) then
|
||||
-- global is special, all other sections have sub-entrys
|
||||
-- also don't delete empty profiles on main dbs, only on namespaces
|
||||
if section ~= "global" and (section ~= "profiles" or rawget(db, "parent")) then
|
||||
for key in pairs(sv[section]) do
|
||||
if not next(sv[section][key]) then
|
||||
sv[section][key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
if not next(sv[section]) then
|
||||
sv[section] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
AceDB.frame:RegisterEvent("PLAYER_LOGOUT")
|
||||
AceDB.frame:SetScript("OnEvent", logoutHandler)
|
||||
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
AceDB Object Method Definitions
|
||||
---------------------------------------------------------------------------]]
|
||||
|
||||
--- Sets the defaults table for the given database object by clearing any
|
||||
-- that are currently set, and then setting the new defaults.
|
||||
-- @param defaults A table of defaults for this database
|
||||
function DBObjectLib:RegisterDefaults(defaults)
|
||||
if defaults and type(defaults) ~= "table" then
|
||||
error(("Usage: AceDBObject:RegisterDefaults(defaults): 'defaults' - table or nil expected, got %q."):format(type(defaults)), 2)
|
||||
end
|
||||
|
||||
validateDefaults(defaults, self.keys)
|
||||
|
||||
-- Remove any currently set defaults
|
||||
if self.defaults then
|
||||
for section,key in pairs(self.keys) do
|
||||
if self.defaults[section] and rawget(self, section) then
|
||||
removeDefaults(self[section], self.defaults[section])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Set the DBObject.defaults table
|
||||
self.defaults = defaults
|
||||
|
||||
-- Copy in any defaults, only touching those sections already created
|
||||
if defaults then
|
||||
for section,key in pairs(self.keys) do
|
||||
if defaults[section] and rawget(self, section) then
|
||||
copyDefaults(self[section], defaults[section])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Changes the profile of the database and all of it's namespaces to the
|
||||
-- supplied named profile
|
||||
-- @param name The name of the profile to set as the current profile
|
||||
function DBObjectLib:SetProfile(name)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:SetProfile(name): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
|
||||
-- changing to the same profile, dont do anything
|
||||
if name == self.keys.profile then return end
|
||||
|
||||
local oldProfile = self.profile
|
||||
local defaults = self.defaults and self.defaults.profile
|
||||
|
||||
-- Callback: OnProfileShutdown, database
|
||||
self.callbacks:Fire("OnProfileShutdown", self)
|
||||
|
||||
if oldProfile and defaults then
|
||||
-- Remove the defaults from the old profile
|
||||
removeDefaults(oldProfile, defaults)
|
||||
end
|
||||
|
||||
self.profile = nil
|
||||
self.keys["profile"] = name
|
||||
|
||||
-- if the storage exists, save the new profile
|
||||
-- this won't exist on namespaces.
|
||||
if self.sv.profileKeys then
|
||||
self.sv.profileKeys[charKey] = name
|
||||
end
|
||||
|
||||
-- populate to child namespaces
|
||||
if self.children then
|
||||
for _, db in pairs(self.children) do
|
||||
DBObjectLib.SetProfile(db, name)
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileChanged, database, newProfileKey
|
||||
self.callbacks:Fire("OnProfileChanged", self, name)
|
||||
end
|
||||
|
||||
--- Returns a table with the names of the existing profiles in the database.
|
||||
-- You can optionally supply a table to re-use for this purpose.
|
||||
-- @param tbl A table to store the profile names in (optional)
|
||||
function DBObjectLib:GetProfiles(tbl)
|
||||
if tbl and type(tbl) ~= "table" then
|
||||
error(("Usage: AceDBObject:GetProfiles(tbl): 'tbl' - table or nil expected, got %q."):format(type(tbl)), 2)
|
||||
end
|
||||
|
||||
-- Clear the container table
|
||||
if tbl then
|
||||
for k,v in pairs(tbl) do tbl[k] = nil end
|
||||
else
|
||||
tbl = {}
|
||||
end
|
||||
|
||||
local curProfile = self.keys.profile
|
||||
|
||||
local i = 0
|
||||
for profileKey in pairs(self.profiles) do
|
||||
i = i + 1
|
||||
tbl[i] = profileKey
|
||||
if curProfile and profileKey == curProfile then curProfile = nil end
|
||||
end
|
||||
|
||||
-- Add the current profile, if it hasn't been created yet
|
||||
if curProfile then
|
||||
i = i + 1
|
||||
tbl[i] = curProfile
|
||||
end
|
||||
|
||||
return tbl, i
|
||||
end
|
||||
|
||||
--- Returns the current profile name used by the database
|
||||
function DBObjectLib:GetCurrentProfile()
|
||||
return self.keys.profile
|
||||
end
|
||||
|
||||
--- Deletes a named profile. This profile must not be the active profile.
|
||||
-- @param name The name of the profile to be deleted
|
||||
-- @param silent If true, do not raise an error when the profile does not exist
|
||||
function DBObjectLib:DeleteProfile(name, silent)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:DeleteProfile(name): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
|
||||
if self.keys.profile == name then
|
||||
error(("Cannot delete the active profile (%q) in an AceDBObject."):format(name), 2)
|
||||
end
|
||||
|
||||
if not rawget(self.profiles, name) and not silent then
|
||||
error(("Cannot delete profile %q as it does not exist."):format(name), 2)
|
||||
end
|
||||
|
||||
self.profiles[name] = nil
|
||||
|
||||
-- populate to child namespaces
|
||||
if self.children then
|
||||
for _, db in pairs(self.children) do
|
||||
DBObjectLib.DeleteProfile(db, name, true)
|
||||
end
|
||||
end
|
||||
|
||||
-- switch all characters that use this profile back to the default
|
||||
if self.sv.profileKeys then
|
||||
for key, profile in pairs(self.sv.profileKeys) do
|
||||
if profile == name then
|
||||
self.sv.profileKeys[key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileDeleted, database, profileKey
|
||||
self.callbacks:Fire("OnProfileDeleted", self, name)
|
||||
end
|
||||
|
||||
--- Copies a named profile into the current profile, overwriting any conflicting
|
||||
-- settings.
|
||||
-- @param name The name of the profile to be copied into the current profile
|
||||
-- @param silent If true, do not raise an error when the profile does not exist
|
||||
function DBObjectLib:CopyProfile(name, silent)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:CopyProfile(name): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
|
||||
if name == self.keys.profile then
|
||||
error(("Cannot have the same source and destination profiles (%q)."):format(name), 2)
|
||||
end
|
||||
|
||||
if not rawget(self.profiles, name) and not silent then
|
||||
error(("Cannot copy profile %q as it does not exist."):format(name), 2)
|
||||
end
|
||||
|
||||
-- Reset the profile before copying
|
||||
DBObjectLib.ResetProfile(self, nil, true)
|
||||
|
||||
local profile = self.profile
|
||||
local source = self.profiles[name]
|
||||
|
||||
copyTable(source, profile)
|
||||
|
||||
-- populate to child namespaces
|
||||
if self.children then
|
||||
for _, db in pairs(self.children) do
|
||||
DBObjectLib.CopyProfile(db, name, true)
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileCopied, database, sourceProfileKey
|
||||
self.callbacks:Fire("OnProfileCopied", self, name)
|
||||
end
|
||||
|
||||
--- Resets the current profile to the default values (if specified).
|
||||
-- @param noChildren if set to true, the reset will not be populated to the child namespaces of this DB object
|
||||
-- @param noCallbacks if set to true, won't fire the OnProfileReset callback
|
||||
function DBObjectLib:ResetProfile(noChildren, noCallbacks)
|
||||
local profile = self.profile
|
||||
|
||||
for k,v in pairs(profile) do
|
||||
profile[k] = nil
|
||||
end
|
||||
|
||||
local defaults = self.defaults and self.defaults.profile
|
||||
if defaults then
|
||||
copyDefaults(profile, defaults)
|
||||
end
|
||||
|
||||
-- populate to child namespaces
|
||||
if self.children and not noChildren then
|
||||
for _, db in pairs(self.children) do
|
||||
DBObjectLib.ResetProfile(db, nil, noCallbacks)
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileReset, database
|
||||
if not noCallbacks then
|
||||
self.callbacks:Fire("OnProfileReset", self)
|
||||
end
|
||||
end
|
||||
|
||||
--- Resets the entire database, using the string defaultProfile as the new default
|
||||
-- profile.
|
||||
-- @param defaultProfile The profile name to use as the default
|
||||
function DBObjectLib:ResetDB(defaultProfile)
|
||||
if defaultProfile and type(defaultProfile) ~= "string" then
|
||||
error(("Usage: AceDBObject:ResetDB(defaultProfile): 'defaultProfile' - string or nil expected, got %q."):format(type(defaultProfile)), 2)
|
||||
end
|
||||
|
||||
local sv = self.sv
|
||||
for k,v in pairs(sv) do
|
||||
sv[k] = nil
|
||||
end
|
||||
|
||||
initdb(sv, self.defaults, defaultProfile, self)
|
||||
|
||||
-- fix the child namespaces
|
||||
if self.children then
|
||||
if not sv.namespaces then sv.namespaces = {} end
|
||||
for name, db in pairs(self.children) do
|
||||
if not sv.namespaces[name] then sv.namespaces[name] = {} end
|
||||
initdb(sv.namespaces[name], db.defaults, self.keys.profile, db, self)
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnDatabaseReset, database
|
||||
self.callbacks:Fire("OnDatabaseReset", self)
|
||||
-- Callback: OnProfileChanged, database, profileKey
|
||||
self.callbacks:Fire("OnProfileChanged", self, self.keys["profile"])
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Creates a new database namespace, directly tied to the database. This
|
||||
-- is a full scale database in it's own rights other than the fact that
|
||||
-- it cannot control its profile individually
|
||||
-- @param name The name of the new namespace
|
||||
-- @param defaults A table of values to use as defaults
|
||||
function DBObjectLib:RegisterNamespace(name, defaults)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:RegisterNamespace(name, defaults): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
if defaults and type(defaults) ~= "table" then
|
||||
error(("Usage: AceDBObject:RegisterNamespace(name, defaults): 'defaults' - table or nil expected, got %q."):format(type(defaults)), 2)
|
||||
end
|
||||
if self.children and self.children[name] then
|
||||
error(("Usage: AceDBObject:RegisterNamespace(name, defaults): 'name' - a namespace called %q already exists."):format(name), 2)
|
||||
end
|
||||
|
||||
local sv = self.sv
|
||||
if not sv.namespaces then sv.namespaces = {} end
|
||||
if not sv.namespaces[name] then
|
||||
sv.namespaces[name] = {}
|
||||
end
|
||||
|
||||
local newDB = initdb(sv.namespaces[name], defaults, self.keys.profile, nil, self)
|
||||
|
||||
if not self.children then self.children = {} end
|
||||
self.children[name] = newDB
|
||||
return newDB
|
||||
end
|
||||
|
||||
--- Returns an already existing namespace from the database object.
|
||||
-- @param name The name of the new namespace
|
||||
-- @param silent if true, the addon is optional, silently return nil if its not found
|
||||
-- @usage
|
||||
-- local namespace = self.db:GetNamespace('namespace')
|
||||
-- @return the namespace object if found
|
||||
function DBObjectLib:GetNamespace(name, silent)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:GetNamespace(name): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
if not silent and not (self.children and self.children[name]) then
|
||||
error(("Usage: AceDBObject:GetNamespace(name): 'name' - namespace %q does not exist."):format(name), 2)
|
||||
end
|
||||
if not self.children then self.children = {} end
|
||||
return self.children[name]
|
||||
end
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
AceDB Exposed Methods
|
||||
---------------------------------------------------------------------------]]
|
||||
|
||||
--- Creates a new database object that can be used to handle database settings and profiles.
|
||||
-- By default, an empty DB is created, using a character specific profile.
|
||||
--
|
||||
-- You can override the default profile used by passing any profile name as the third argument,
|
||||
-- or by passing //true// as the third argument to use a globally shared profile called "Default".
|
||||
--
|
||||
-- Note that there is no token replacement in the default profile name, passing a defaultProfile as "char"
|
||||
-- will use a profile named "char", and not a character-specific profile.
|
||||
-- @param tbl The name of variable, or table to use for the database
|
||||
-- @param defaults A table of database defaults
|
||||
-- @param defaultProfile The name of the default profile. If not set, a character specific profile will be used as the default.
|
||||
-- You can also pass //true// to use a shared global profile called "Default".
|
||||
-- @usage
|
||||
-- -- Create an empty DB using a character-specific default profile.
|
||||
-- self.db = LibStub("AceDB-3.0"):New("MyAddonDB")
|
||||
-- @usage
|
||||
-- -- Create a DB using defaults and using a shared default profile
|
||||
-- self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
|
||||
function AceDB:New(tbl, defaults, defaultProfile)
|
||||
if type(tbl) == "string" then
|
||||
local name = tbl
|
||||
tbl = _G[name]
|
||||
if not tbl then
|
||||
tbl = {}
|
||||
_G[name] = tbl
|
||||
end
|
||||
end
|
||||
|
||||
if type(tbl) ~= "table" then
|
||||
error(("Usage: AceDB:New(tbl, defaults, defaultProfile): 'tbl' - table expected, got %q."):format(type(tbl)), 2)
|
||||
end
|
||||
|
||||
if defaults and type(defaults) ~= "table" then
|
||||
error(("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaults' - table expected, got %q."):format(type(defaults)), 2)
|
||||
end
|
||||
|
||||
if defaultProfile and type(defaultProfile) ~= "string" and defaultProfile ~= true then
|
||||
error(("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaultProfile' - string or true expected, got %q."):format(type(defaultProfile)), 2)
|
||||
end
|
||||
|
||||
return initdb(tbl, defaults, defaultProfile)
|
||||
end
|
||||
|
||||
-- upgrade existing databases
|
||||
for db in pairs(AceDB.db_registry) do
|
||||
if not db.parent then
|
||||
for name,func in pairs(DBObjectLib) do
|
||||
db[name] = func
|
||||
end
|
||||
else
|
||||
db.RegisterDefaults = DBObjectLib.RegisterDefaults
|
||||
db.ResetProfile = DBObjectLib.ResetProfile
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="AceDB-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,126 @@
|
||||
--- AceEvent-3.0 provides event registration and secure dispatching.
|
||||
-- All dispatching is done using **CallbackHandler-1.0**. AceEvent is a simple wrapper around
|
||||
-- CallbackHandler, and dispatches all game events or addon message to the registrees.
|
||||
--
|
||||
-- **AceEvent-3.0** can be embeded into your addon, either explicitly by calling AceEvent:Embed(MyAddon) or by
|
||||
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
|
||||
-- and can be accessed directly, without having to explicitly call AceEvent itself.\\
|
||||
-- It is recommended to embed AceEvent, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceEvent.
|
||||
-- @class file
|
||||
-- @name AceEvent-3.0
|
||||
-- @release $Id$
|
||||
local CallbackHandler = LibStub("CallbackHandler-1.0")
|
||||
|
||||
local MAJOR, MINOR = "AceEvent-3.0", 4
|
||||
local AceEvent = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceEvent then return end
|
||||
|
||||
-- Lua APIs
|
||||
local pairs = pairs
|
||||
|
||||
AceEvent.frame = AceEvent.frame or CreateFrame("Frame", "AceEvent30Frame") -- our event frame
|
||||
AceEvent.embeds = AceEvent.embeds or {} -- what objects embed this lib
|
||||
|
||||
-- APIs and registry for blizzard events, using CallbackHandler lib
|
||||
if not AceEvent.events then
|
||||
AceEvent.events = CallbackHandler:New(AceEvent,
|
||||
"RegisterEvent", "UnregisterEvent", "UnregisterAllEvents")
|
||||
end
|
||||
|
||||
function AceEvent.events:OnUsed(target, eventname)
|
||||
AceEvent.frame:RegisterEvent(eventname)
|
||||
end
|
||||
|
||||
function AceEvent.events:OnUnused(target, eventname)
|
||||
AceEvent.frame:UnregisterEvent(eventname)
|
||||
end
|
||||
|
||||
|
||||
-- APIs and registry for IPC messages, using CallbackHandler lib
|
||||
if not AceEvent.messages then
|
||||
AceEvent.messages = CallbackHandler:New(AceEvent,
|
||||
"RegisterMessage", "UnregisterMessage", "UnregisterAllMessages"
|
||||
)
|
||||
AceEvent.SendMessage = AceEvent.messages.Fire
|
||||
end
|
||||
|
||||
--- embedding and embed handling
|
||||
local mixins = {
|
||||
"RegisterEvent", "UnregisterEvent",
|
||||
"RegisterMessage", "UnregisterMessage",
|
||||
"SendMessage",
|
||||
"UnregisterAllEvents", "UnregisterAllMessages",
|
||||
}
|
||||
|
||||
--- Register for a Blizzard Event.
|
||||
-- The callback will be called with the optional `arg` as the first argument (if supplied), and the event name as the second (or first, if no arg was supplied)
|
||||
-- Any arguments to the event will be passed on after that.
|
||||
-- @name AceEvent:RegisterEvent
|
||||
-- @class function
|
||||
-- @paramsig event[, callback [, arg]]
|
||||
-- @param event The event to register for
|
||||
-- @param callback The callback function to call when the event is triggered (funcref or method, defaults to a method with the event name)
|
||||
-- @param arg An optional argument to pass to the callback function
|
||||
|
||||
--- Unregister an event.
|
||||
-- @name AceEvent:UnregisterEvent
|
||||
-- @class function
|
||||
-- @paramsig event
|
||||
-- @param event The event to unregister
|
||||
|
||||
--- Register for a custom AceEvent-internal message.
|
||||
-- The callback will be called with the optional `arg` as the first argument (if supplied), and the event name as the second (or first, if no arg was supplied)
|
||||
-- Any arguments to the event will be passed on after that.
|
||||
-- @name AceEvent:RegisterMessage
|
||||
-- @class function
|
||||
-- @paramsig message[, callback [, arg]]
|
||||
-- @param message The message to register for
|
||||
-- @param callback The callback function to call when the message is triggered (funcref or method, defaults to a method with the event name)
|
||||
-- @param arg An optional argument to pass to the callback function
|
||||
|
||||
--- Unregister a message
|
||||
-- @name AceEvent:UnregisterMessage
|
||||
-- @class function
|
||||
-- @paramsig message
|
||||
-- @param message The message to unregister
|
||||
|
||||
--- Send a message over the AceEvent-3.0 internal message system to other addons registered for this message.
|
||||
-- @name AceEvent:SendMessage
|
||||
-- @class function
|
||||
-- @paramsig message, ...
|
||||
-- @param message The message to send
|
||||
-- @param ... Any arguments to the message
|
||||
|
||||
|
||||
-- Embeds AceEvent into the target object making the functions from the mixins list available on target:..
|
||||
-- @param target target object to embed AceEvent in
|
||||
function AceEvent:Embed(target)
|
||||
for k, v in pairs(mixins) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeds[target] = true
|
||||
return target
|
||||
end
|
||||
|
||||
-- AceEvent:OnEmbedDisable( target )
|
||||
-- target (object) - target object that is being disabled
|
||||
--
|
||||
-- Unregister all events messages etc when the target disables.
|
||||
-- this method should be called by the target manually or by an addon framework
|
||||
function AceEvent:OnEmbedDisable(target)
|
||||
target:UnregisterAllEvents()
|
||||
target:UnregisterAllMessages()
|
||||
end
|
||||
|
||||
-- Script to fire blizzard events into the event listeners
|
||||
local events = AceEvent.events
|
||||
AceEvent.frame:SetScript("OnEvent", function(this, event, ...)
|
||||
events:Fire(event, ...)
|
||||
end)
|
||||
|
||||
--- Finally: upgrade our old embeds
|
||||
for target, v in pairs(AceEvent.embeds) do
|
||||
AceEvent:Embed(target)
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="AceEvent-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,511 @@
|
||||
--- **AceHook-3.0** offers safe Hooking/Unhooking of functions, methods and frame scripts.
|
||||
-- Using AceHook-3.0 is recommended when you need to unhook your hooks again, so the hook chain isn't broken
|
||||
-- when you manually restore the original function.
|
||||
--
|
||||
-- **AceHook-3.0** can be embeded into your addon, either explicitly by calling AceHook:Embed(MyAddon) or by
|
||||
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
|
||||
-- and can be accessed directly, without having to explicitly call AceHook itself.\\
|
||||
-- It is recommended to embed AceHook, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceHook.
|
||||
-- @class file
|
||||
-- @name AceHook-3.0
|
||||
-- @release $Id$
|
||||
local ACEHOOK_MAJOR, ACEHOOK_MINOR = "AceHook-3.0", 8
|
||||
local AceHook, oldminor = LibStub:NewLibrary(ACEHOOK_MAJOR, ACEHOOK_MINOR)
|
||||
|
||||
if not AceHook then return end -- No upgrade needed
|
||||
|
||||
AceHook.embeded = AceHook.embeded or {}
|
||||
AceHook.registry = AceHook.registry or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end })
|
||||
AceHook.handlers = AceHook.handlers or {}
|
||||
AceHook.actives = AceHook.actives or {}
|
||||
AceHook.scripts = AceHook.scripts or {}
|
||||
AceHook.onceSecure = AceHook.onceSecure or {}
|
||||
AceHook.hooks = AceHook.hooks or {}
|
||||
|
||||
-- local upvalues
|
||||
local registry = AceHook.registry
|
||||
local handlers = AceHook.handlers
|
||||
local actives = AceHook.actives
|
||||
local scripts = AceHook.scripts
|
||||
local onceSecure = AceHook.onceSecure
|
||||
|
||||
-- Lua APIs
|
||||
local pairs, next, type = pairs, next, type
|
||||
local format = string.format
|
||||
local assert, error = assert, error
|
||||
|
||||
-- WoW APIs
|
||||
local issecurevariable, hooksecurefunc = issecurevariable, hooksecurefunc
|
||||
local _G = _G
|
||||
|
||||
-- functions for later definition
|
||||
local donothing, createHook, hook
|
||||
|
||||
local protectedScripts = {
|
||||
OnClick = true,
|
||||
}
|
||||
|
||||
-- upgrading of embeded is done at the bottom of the file
|
||||
|
||||
local mixins = {
|
||||
"Hook", "SecureHook",
|
||||
"HookScript", "SecureHookScript",
|
||||
"Unhook", "UnhookAll",
|
||||
"IsHooked",
|
||||
"RawHook", "RawHookScript"
|
||||
}
|
||||
|
||||
-- AceHook:Embed( target )
|
||||
-- target (object) - target object to embed AceHook in
|
||||
--
|
||||
-- Embeds AceEevent into the target object making the functions from the mixins list available on target:..
|
||||
function AceHook:Embed( target )
|
||||
for k, v in pairs( mixins ) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeded[target] = true
|
||||
-- inject the hooks table safely
|
||||
target.hooks = target.hooks or {}
|
||||
return target
|
||||
end
|
||||
|
||||
-- AceHook:OnEmbedDisable( target )
|
||||
-- target (object) - target object that is being disabled
|
||||
--
|
||||
-- Unhooks all hooks when the target disables.
|
||||
-- this method should be called by the target manually or by an addon framework
|
||||
function AceHook:OnEmbedDisable( target )
|
||||
target:UnhookAll()
|
||||
end
|
||||
|
||||
function createHook(self, handler, orig, secure, failsafe)
|
||||
local uid
|
||||
local method = type(handler) == "string"
|
||||
if failsafe and not secure then
|
||||
-- failsafe hook creation
|
||||
uid = function(...)
|
||||
if actives[uid] then
|
||||
if method then
|
||||
self[handler](self, ...)
|
||||
else
|
||||
handler(...)
|
||||
end
|
||||
end
|
||||
return orig(...)
|
||||
end
|
||||
-- /failsafe hook
|
||||
else
|
||||
-- all other hooks
|
||||
uid = function(...)
|
||||
if actives[uid] then
|
||||
if method then
|
||||
return self[handler](self, ...)
|
||||
else
|
||||
return handler(...)
|
||||
end
|
||||
elseif not secure then -- backup on non secure
|
||||
return orig(...)
|
||||
end
|
||||
end
|
||||
-- /hook
|
||||
end
|
||||
return uid
|
||||
end
|
||||
|
||||
function donothing() end
|
||||
|
||||
function hook(self, obj, method, handler, script, secure, raw, forceSecure, usage)
|
||||
if not handler then handler = method end
|
||||
|
||||
-- These asserts make sure AceHooks's devs play by the rules.
|
||||
assert(not script or type(script) == "boolean")
|
||||
assert(not secure or type(secure) == "boolean")
|
||||
assert(not raw or type(raw) == "boolean")
|
||||
assert(not forceSecure or type(forceSecure) == "boolean")
|
||||
assert(usage)
|
||||
|
||||
-- Error checking Battery!
|
||||
if obj and type(obj) ~= "table" then
|
||||
error(format("%s: 'object' - nil or table expected got %s", usage, type(obj)), 3)
|
||||
end
|
||||
if type(method) ~= "string" then
|
||||
error(format("%s: 'method' - string expected got %s", usage, type(method)), 3)
|
||||
end
|
||||
if type(handler) ~= "string" and type(handler) ~= "function" then
|
||||
error(format("%s: 'handler' - nil, string, or function expected got %s", usage, type(handler)), 3)
|
||||
end
|
||||
if type(handler) == "string" and type(self[handler]) ~= "function" then
|
||||
error(format("%s: 'handler' - Handler specified does not exist at self[handler]", usage), 3)
|
||||
end
|
||||
if script then
|
||||
if not obj or not obj.GetScript or not obj:HasScript(method) then
|
||||
error(format("%s: You can only hook a script on a frame object", usage), 3)
|
||||
end
|
||||
if not secure and obj.IsProtected and obj:IsProtected() and protectedScripts[method] then
|
||||
error(format("Cannot hook secure script %q; Use SecureHookScript(obj, method, [handler]) instead.", method), 3)
|
||||
end
|
||||
else
|
||||
local issecure
|
||||
if obj then
|
||||
issecure = onceSecure[obj] and onceSecure[obj][method] or issecurevariable(obj, method)
|
||||
else
|
||||
issecure = onceSecure[method] or issecurevariable(method)
|
||||
end
|
||||
if issecure then
|
||||
if forceSecure then
|
||||
if obj then
|
||||
onceSecure[obj] = onceSecure[obj] or {}
|
||||
onceSecure[obj][method] = true
|
||||
else
|
||||
onceSecure[method] = true
|
||||
end
|
||||
elseif not secure then
|
||||
error(format("%s: Attempt to hook secure function %s. Use `SecureHook' or add `true' to the argument list to override.", usage, method), 3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local uid
|
||||
if obj then
|
||||
uid = registry[self][obj] and registry[self][obj][method]
|
||||
else
|
||||
uid = registry[self][method]
|
||||
end
|
||||
|
||||
if uid then
|
||||
if actives[uid] then
|
||||
-- Only two sane choices exist here. We either a) error 100% of the time or b) always unhook and then hook
|
||||
-- choice b would likely lead to odd debuging conditions or other mysteries so we're going with a.
|
||||
error(format("Attempting to rehook already active hook %s.", method))
|
||||
end
|
||||
|
||||
if handlers[uid] == handler then -- turn on a decative hook, note enclosures break this ability, small memory leak
|
||||
actives[uid] = true
|
||||
return
|
||||
elseif obj then -- is there any reason not to call unhook instead of doing the following several lines?
|
||||
if self.hooks and self.hooks[obj] then
|
||||
self.hooks[obj][method] = nil
|
||||
end
|
||||
registry[self][obj][method] = nil
|
||||
else
|
||||
if self.hooks then
|
||||
self.hooks[method] = nil
|
||||
end
|
||||
registry[self][method] = nil
|
||||
end
|
||||
handlers[uid], actives[uid], scripts[uid] = nil, nil, nil
|
||||
uid = nil
|
||||
end
|
||||
|
||||
local orig
|
||||
if script then
|
||||
orig = obj:GetScript(method) or donothing
|
||||
elseif obj then
|
||||
orig = obj[method]
|
||||
else
|
||||
orig = _G[method]
|
||||
end
|
||||
|
||||
if not orig then
|
||||
error(format("%s: Attempting to hook a non existing target", usage), 3)
|
||||
end
|
||||
|
||||
uid = createHook(self, handler, orig, secure, not (raw or secure))
|
||||
|
||||
if obj then
|
||||
self.hooks[obj] = self.hooks[obj] or {}
|
||||
registry[self][obj] = registry[self][obj] or {}
|
||||
registry[self][obj][method] = uid
|
||||
|
||||
if not secure then
|
||||
self.hooks[obj][method] = orig
|
||||
end
|
||||
|
||||
if script then
|
||||
if not secure then
|
||||
obj:SetScript(method, uid)
|
||||
else
|
||||
obj:HookScript(method, uid)
|
||||
end
|
||||
else
|
||||
if not secure then
|
||||
obj[method] = uid
|
||||
else
|
||||
hooksecurefunc(obj, method, uid)
|
||||
end
|
||||
end
|
||||
else
|
||||
registry[self][method] = uid
|
||||
|
||||
if not secure then
|
||||
_G[method] = uid
|
||||
self.hooks[method] = orig
|
||||
else
|
||||
hooksecurefunc(method, uid)
|
||||
end
|
||||
end
|
||||
|
||||
actives[uid], handlers[uid], scripts[uid] = true, handler, script and true or nil
|
||||
end
|
||||
|
||||
--- Hook a function or a method on an object.
|
||||
-- The hook created will be a "safe hook", that means that your handler will be called
|
||||
-- before the hooked function ("Pre-Hook"), and you don't have to call the original function yourself,
|
||||
-- however you cannot stop the execution of the function, or modify any of the arguments/return values.\\
|
||||
-- This type of hook is typically used if you need to know if some function got called, and don't want to modify it.
|
||||
-- @paramsig [object], method, [handler], [hookSecure]
|
||||
-- @param object The object to hook a method from
|
||||
-- @param method If object was specified, the name of the method, or the name of the function to hook.
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)
|
||||
-- @param hookSecure If true, AceHook will allow hooking of secure functions.
|
||||
-- @usage
|
||||
-- -- create an addon with AceHook embeded
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Hook ActionButton_UpdateHotkeys, overwriting the secure status
|
||||
-- self:Hook("ActionButton_UpdateHotkeys", true)
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:ActionButton_UpdateHotkeys(button, type)
|
||||
-- print(button:GetName() .. " is updating its HotKey")
|
||||
-- end
|
||||
function AceHook:Hook(object, method, handler, hookSecure)
|
||||
if type(object) == "string" then
|
||||
method, handler, hookSecure, object = object, method, handler, nil
|
||||
end
|
||||
|
||||
if handler == true then
|
||||
handler, hookSecure = nil, true
|
||||
end
|
||||
|
||||
hook(self, object, method, handler, false, false, false, hookSecure or false, "Usage: Hook([object], method, [handler], [hookSecure])")
|
||||
end
|
||||
|
||||
--- RawHook a function or a method on an object.
|
||||
-- The hook created will be a "raw hook", that means that your handler will completly replace
|
||||
-- the original function, and your handler has to call the original function (or not, depending on your intentions).\\
|
||||
-- The original function will be stored in `self.hooks[object][method]` or `self.hooks[functionName]` respectively.\\
|
||||
-- This type of hook can be used for all purposes, and is usually the most common case when you need to modify arguments
|
||||
-- or want to control execution of the original function.
|
||||
-- @paramsig [object], method, [handler], [hookSecure]
|
||||
-- @param object The object to hook a method from
|
||||
-- @param method If object was specified, the name of the method, or the name of the function to hook.
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)
|
||||
-- @param hookSecure If true, AceHook will allow hooking of secure functions.
|
||||
-- @usage
|
||||
-- -- create an addon with AceHook embeded
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Hook ActionButton_UpdateHotkeys, overwriting the secure status
|
||||
-- self:RawHook("ActionButton_UpdateHotkeys", true)
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:ActionButton_UpdateHotkeys(button, type)
|
||||
-- if button:GetName() == "MyButton" then
|
||||
-- -- do stuff here
|
||||
-- else
|
||||
-- self.hooks.ActionButton_UpdateHotkeys(button, type)
|
||||
-- end
|
||||
-- end
|
||||
function AceHook:RawHook(object, method, handler, hookSecure)
|
||||
if type(object) == "string" then
|
||||
method, handler, hookSecure, object = object, method, handler, nil
|
||||
end
|
||||
|
||||
if handler == true then
|
||||
handler, hookSecure = nil, true
|
||||
end
|
||||
|
||||
hook(self, object, method, handler, false, false, true, hookSecure or false, "Usage: RawHook([object], method, [handler], [hookSecure])")
|
||||
end
|
||||
|
||||
--- SecureHook a function or a method on an object.
|
||||
-- This function is a wrapper around the `hooksecurefunc` function in the WoW API. Using AceHook
|
||||
-- extends the functionality of secure hooks, and adds the ability to unhook once the hook isn't
|
||||
-- required anymore, or the addon is being disabled.\\
|
||||
-- Secure Hooks should be used if the secure-status of the function is vital to its function,
|
||||
-- and taint would block execution. Secure Hooks are always called after the original function was called
|
||||
-- ("Post Hook"), and you cannot modify the arguments, return values or control the execution.
|
||||
-- @paramsig [object], method, [handler]
|
||||
-- @param object The object to hook a method from
|
||||
-- @param method If object was specified, the name of the method, or the name of the function to hook.
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)
|
||||
function AceHook:SecureHook(object, method, handler)
|
||||
if type(object) == "string" then
|
||||
method, handler, object = object, method, nil
|
||||
end
|
||||
|
||||
hook(self, object, method, handler, false, true, false, false, "Usage: SecureHook([object], method, [handler])")
|
||||
end
|
||||
|
||||
--- Hook a script handler on a frame.
|
||||
-- The hook created will be a "safe hook", that means that your handler will be called
|
||||
-- before the hooked script ("Pre-Hook"), and you don't have to call the original function yourself,
|
||||
-- however you cannot stop the execution of the function, or modify any of the arguments/return values.\\
|
||||
-- This is the frame script equivalent of the :Hook safe-hook. It would typically be used to be notified
|
||||
-- when a certain event happens to a frame.
|
||||
-- @paramsig frame, script, [handler]
|
||||
-- @param frame The Frame to hook the script on
|
||||
-- @param script The script to hook
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script)
|
||||
-- @usage
|
||||
-- -- create an addon with AceHook embeded
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Hook the OnShow of FriendsFrame
|
||||
-- self:HookScript(FriendsFrame, "OnShow", "FriendsFrameOnShow")
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:FriendsFrameOnShow(frame)
|
||||
-- print("The FriendsFrame was shown!")
|
||||
-- end
|
||||
function AceHook:HookScript(frame, script, handler)
|
||||
hook(self, frame, script, handler, true, false, false, false, "Usage: HookScript(object, method, [handler])")
|
||||
end
|
||||
|
||||
--- RawHook a script handler on a frame.
|
||||
-- The hook created will be a "raw hook", that means that your handler will completly replace
|
||||
-- the original script, and your handler has to call the original script (or not, depending on your intentions).\\
|
||||
-- The original script will be stored in `self.hooks[frame][script]`.\\
|
||||
-- This type of hook can be used for all purposes, and is usually the most common case when you need to modify arguments
|
||||
-- or want to control execution of the original script.
|
||||
-- @paramsig frame, script, [handler]
|
||||
-- @param frame The Frame to hook the script on
|
||||
-- @param script The script to hook
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script)
|
||||
-- @usage
|
||||
-- -- create an addon with AceHook embeded
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Hook the OnShow of FriendsFrame
|
||||
-- self:RawHookScript(FriendsFrame, "OnShow", "FriendsFrameOnShow")
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:FriendsFrameOnShow(frame)
|
||||
-- -- Call the original function
|
||||
-- self.hooks[frame].OnShow(frame)
|
||||
-- -- Do our processing
|
||||
-- -- .. stuff
|
||||
-- end
|
||||
function AceHook:RawHookScript(frame, script, handler)
|
||||
hook(self, frame, script, handler, true, false, true, false, "Usage: RawHookScript(object, method, [handler])")
|
||||
end
|
||||
|
||||
--- SecureHook a script handler on a frame.
|
||||
-- This function is a wrapper around the `frame:HookScript` function in the WoW API. Using AceHook
|
||||
-- extends the functionality of secure hooks, and adds the ability to unhook once the hook isn't
|
||||
-- required anymore, or the addon is being disabled.\\
|
||||
-- Secure Hooks should be used if the secure-status of the function is vital to its function,
|
||||
-- and taint would block execution. Secure Hooks are always called after the original function was called
|
||||
-- ("Post Hook"), and you cannot modify the arguments, return values or control the execution.
|
||||
-- @paramsig frame, script, [handler]
|
||||
-- @param frame The Frame to hook the script on
|
||||
-- @param script The script to hook
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script)
|
||||
function AceHook:SecureHookScript(frame, script, handler)
|
||||
hook(self, frame, script, handler, true, true, false, false, "Usage: SecureHookScript(object, method, [handler])")
|
||||
end
|
||||
|
||||
--- Unhook from the specified function, method or script.
|
||||
-- @paramsig [obj], method
|
||||
-- @param obj The object or frame to unhook from
|
||||
-- @param method The name of the method, function or script to unhook from.
|
||||
function AceHook:Unhook(obj, method)
|
||||
local usage = "Usage: Unhook([obj], method)"
|
||||
if type(obj) == "string" then
|
||||
method, obj = obj, nil
|
||||
end
|
||||
|
||||
if obj and type(obj) ~= "table" then
|
||||
error(format("%s: 'obj' - expecting nil or table got %s", usage, type(obj)), 2)
|
||||
end
|
||||
if type(method) ~= "string" then
|
||||
error(format("%s: 'method' - expeting string got %s", usage, type(method)), 2)
|
||||
end
|
||||
|
||||
local uid
|
||||
if obj then
|
||||
uid = registry[self][obj] and registry[self][obj][method]
|
||||
else
|
||||
uid = registry[self][method]
|
||||
end
|
||||
|
||||
if not uid or not actives[uid] then
|
||||
-- Declining to error on an unneeded unhook since the end effect is the same and this would just be annoying.
|
||||
return false
|
||||
end
|
||||
|
||||
actives[uid], handlers[uid] = nil, nil
|
||||
|
||||
if obj then
|
||||
registry[self][obj][method] = nil
|
||||
registry[self][obj] = next(registry[self][obj]) and registry[self][obj] or nil
|
||||
|
||||
-- if the hook reference doesnt exist, then its a secure hook, just bail out and dont do any unhooking
|
||||
if not self.hooks[obj] or not self.hooks[obj][method] then return true end
|
||||
|
||||
if scripts[uid] and obj:GetScript(method) == uid then -- unhooks scripts
|
||||
obj:SetScript(method, self.hooks[obj][method] ~= donothing and self.hooks[obj][method] or nil)
|
||||
scripts[uid] = nil
|
||||
elseif obj and self.hooks[obj] and self.hooks[obj][method] and obj[method] == uid then -- unhooks methods
|
||||
obj[method] = self.hooks[obj][method]
|
||||
end
|
||||
|
||||
self.hooks[obj][method] = nil
|
||||
self.hooks[obj] = next(self.hooks[obj]) and self.hooks[obj] or nil
|
||||
else
|
||||
registry[self][method] = nil
|
||||
|
||||
-- if self.hooks[method] doesn't exist, then this is a SecureHook, just bail out
|
||||
if not self.hooks[method] then return true end
|
||||
|
||||
if self.hooks[method] and _G[method] == uid then -- unhooks functions
|
||||
_G[method] = self.hooks[method]
|
||||
end
|
||||
|
||||
self.hooks[method] = nil
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--- Unhook all existing hooks for this addon.
|
||||
function AceHook:UnhookAll()
|
||||
for key, value in pairs(registry[self]) do
|
||||
if type(key) == "table" then
|
||||
for method in pairs(value) do
|
||||
self:Unhook(key, method)
|
||||
end
|
||||
else
|
||||
self:Unhook(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Check if the specific function, method or script is already hooked.
|
||||
-- @paramsig [obj], method
|
||||
-- @param obj The object or frame to unhook from
|
||||
-- @param method The name of the method, function or script to unhook from.
|
||||
function AceHook:IsHooked(obj, method)
|
||||
-- we don't check if registry[self] exists, this is done by evil magicks in the metatable
|
||||
if type(obj) == "string" then
|
||||
if registry[self][obj] and actives[registry[self][obj]] then
|
||||
return true, handlers[registry[self][obj]]
|
||||
end
|
||||
else
|
||||
if registry[self][obj] and registry[self][obj][method] and actives[registry[self][obj][method]] then
|
||||
return true, handlers[registry[self][obj][method]]
|
||||
end
|
||||
end
|
||||
|
||||
return false, nil
|
||||
end
|
||||
|
||||
--- Upgrade our old embeded
|
||||
for target, v in pairs( AceHook.embeded ) do
|
||||
AceHook:Embed( target )
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="AceHook-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,143 @@
|
||||
--- **AceLocale-3.0** manages localization in addons, allowing for multiple locale to be registered with fallback to the base locale for untranslated strings.
|
||||
-- @class file
|
||||
-- @name AceLocale-3.0
|
||||
-- @release $Id$
|
||||
local MAJOR,MINOR = "AceLocale-3.0-ElvUI", 6
|
||||
|
||||
local AceLocale, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceLocale then return end -- no upgrade needed
|
||||
|
||||
-- Lua APIs
|
||||
local assert, tostring, error = assert, tostring, error
|
||||
local getmetatable, setmetatable, rawset, rawget = getmetatable, setmetatable, rawset, rawget
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: GAME_LOCALE, geterrorhandler
|
||||
|
||||
local gameLocale = GetLocale()
|
||||
if gameLocale == "enGB" then
|
||||
gameLocale = "enUS"
|
||||
end
|
||||
|
||||
AceLocale.apps = AceLocale.apps or {} -- array of ["AppName"]=localetableref
|
||||
AceLocale.appnames = AceLocale.appnames or {} -- array of [localetableref]="AppName"
|
||||
|
||||
-- This metatable is used on all tables returned from GetLocale
|
||||
local readmeta = {
|
||||
__index = function(self, key) -- requesting totally unknown entries: fire off a nonbreaking error and return key
|
||||
rawset(self, key, key) -- only need to see the warning once, really
|
||||
geterrorhandler()(MAJOR..": "..tostring(AceLocale.appnames[self])..": Missing entry for '"..tostring(key).."'")
|
||||
return key
|
||||
end
|
||||
}
|
||||
|
||||
-- This metatable is used on all tables returned from GetLocale if the silent flag is true, it does not issue a warning on unknown keys
|
||||
local readmetasilent = {
|
||||
__index = function(self, key) -- requesting totally unknown entries: return key
|
||||
rawset(self, key, key) -- only need to invoke this function once
|
||||
return key
|
||||
end
|
||||
}
|
||||
|
||||
-- Remember the locale table being registered right now (it gets set by :NewLocale())
|
||||
-- NOTE: Do never try to register 2 locale tables at once and mix their definition.
|
||||
local registering
|
||||
|
||||
-- local assert false function
|
||||
local assertfalse = function() assert(false) end
|
||||
|
||||
-- This metatable proxy is used when registering nondefault locales
|
||||
local writeproxy = setmetatable({}, {
|
||||
__newindex = function(self, key, value)
|
||||
rawset(registering, key, value == true and key or value) -- assigning values: replace 'true' with key string
|
||||
end,
|
||||
__index = assertfalse
|
||||
})
|
||||
|
||||
-- This metatable proxy is used when registering the default locale.
|
||||
-- It refuses to overwrite existing values
|
||||
-- Reason 1: Allows loading locales in any order
|
||||
-- Reason 2: If 2 modules have the same string, but only the first one to be
|
||||
-- loaded has a translation for the current locale, the translation
|
||||
-- doesn't get overwritten.
|
||||
--
|
||||
local writedefaultproxy = setmetatable({}, {
|
||||
__newindex = function(self, key, value)
|
||||
if not rawget(registering, key) then
|
||||
rawset(registering, key, value == true and key or value)
|
||||
end
|
||||
end,
|
||||
__index = assertfalse
|
||||
})
|
||||
|
||||
--- Register a new locale (or extend an existing one) for the specified application.
|
||||
-- :NewLocale will return a table you can fill your locale into, or nil if the locale isn't needed for the players
|
||||
-- game locale.
|
||||
-- @paramsig application, locale[, isDefault[, silent]]
|
||||
-- @param application Unique name of addon / module
|
||||
-- @param locale Name of the locale to register, e.g. "enUS", "deDE", etc.
|
||||
-- @param isDefault If this is the default locale being registered (your addon is written in this language, generally enUS)
|
||||
-- @param silent If true, the locale will not issue warnings for missing keys. Must be set on the first locale registered. If set to "raw", nils will be returned for unknown keys (no metatable used).
|
||||
-- @usage
|
||||
-- -- enUS.lua
|
||||
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "enUS", true)
|
||||
-- L["string1"] = true
|
||||
--
|
||||
-- -- deDE.lua
|
||||
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "deDE")
|
||||
-- if not L then return end
|
||||
-- L["string1"] = "Zeichenkette1"
|
||||
-- @return Locale Table to add localizations to, or nil if the current locale is not required.
|
||||
function AceLocale:NewLocale(application, locale, isDefault, silent)
|
||||
local app = AceLocale.apps[application]
|
||||
|
||||
if silent and app and getmetatable(app) ~= readmetasilent then
|
||||
geterrorhandler()("Usage: NewLocale(application, locale[, isDefault[, silent]]): 'silent' must be specified for the first locale registered")
|
||||
end
|
||||
|
||||
if not app then
|
||||
if silent=="raw" then
|
||||
app = {}
|
||||
else
|
||||
app = setmetatable({}, silent and readmetasilent or readmeta)
|
||||
end
|
||||
AceLocale.apps[application] = app
|
||||
AceLocale.appnames[app] = application
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
if (not app[locale]) or (app[locale] and type(app[locale]) ~= 'table') then
|
||||
-- app[locale] = setmetatable({}, silent and readmetasilent or readmeta) -- To find missing keys
|
||||
app[locale] = setmetatable({}, readmetasilent)
|
||||
end
|
||||
|
||||
registering = app[locale] -- remember globally for writeproxy and writedefaultproxy
|
||||
-- end block
|
||||
|
||||
if isDefault then
|
||||
return writedefaultproxy
|
||||
end
|
||||
|
||||
return writeproxy
|
||||
end
|
||||
|
||||
--- Returns localizations for the current locale (or default locale if translations are missing).
|
||||
-- Errors if nothing is registered (spank developer, not just a missing translation)
|
||||
-- @param application Unique name of addon / module
|
||||
-- @param silent If true, the locale is optional, silently return nil if it's not found (defaults to false, optional)
|
||||
-- @return The locale table for the current language.
|
||||
--- Modified by ElvUI to add `locale` as second arg
|
||||
function AceLocale:GetLocale(application, locale, silent)
|
||||
if type(locale) == "boolean" then
|
||||
silent = locale
|
||||
locale = gameLocale
|
||||
end
|
||||
|
||||
if not silent and not AceLocale.apps[application] then
|
||||
error("Usage: GetLocale(application[,locale[, silent]]): 'application' - No locales registered for '"..tostring(application).."'", 2)
|
||||
end
|
||||
|
||||
return AceLocale.apps[application][locale] or AceLocale.apps[application][gameLocale] -- Just in case the table doesn't exist it reverts to default
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="AceLocale-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,281 @@
|
||||
--- **AceSerializer-3.0** can serialize any variable (except functions or userdata) into a string format,
|
||||
-- that can be send over the addon comm channel. AceSerializer was designed to keep all data intact, especially
|
||||
-- very large numbers or floating point numbers, and table structures. The only caveat currently is, that multiple
|
||||
-- references to the same table will be send individually.
|
||||
--
|
||||
-- **AceSerializer-3.0** can be embeded into your addon, either explicitly by calling AceSerializer:Embed(MyAddon) or by
|
||||
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
|
||||
-- and can be accessed directly, without having to explicitly call AceSerializer itself.\\
|
||||
-- It is recommended to embed AceSerializer, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceSerializer.
|
||||
-- @class file
|
||||
-- @name AceSerializer-3.0
|
||||
-- @release $Id$
|
||||
local MAJOR,MINOR = "AceSerializer-3.0", 3
|
||||
local AceSerializer, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceSerializer then return end
|
||||
|
||||
-- Lua APIs
|
||||
local strbyte, strchar, gsub, gmatch, format = string.byte, string.char, string.gsub, string.gmatch, string.format
|
||||
local assert, error, pcall = assert, error, pcall
|
||||
local type, tostring, tonumber = type, tostring, tonumber
|
||||
local pairs, select, frexp = pairs, select, math.frexp
|
||||
local tconcat = table.concat
|
||||
|
||||
-- quick copies of string representations of wonky numbers
|
||||
local serNaN = tostring(0/0)
|
||||
local serInf = tostring(1/0)
|
||||
local serNegInf = tostring(-1/0)
|
||||
|
||||
|
||||
-- Serialization functions
|
||||
|
||||
local function SerializeStringHelper(ch) -- Used by SerializeValue for strings
|
||||
-- We use \126 ("~") as an escape character for all nonprints plus a few more
|
||||
local n = strbyte(ch)
|
||||
if n==30 then -- v3 / ticket 115: catch a nonprint that ends up being "~^" when encoded... DOH
|
||||
return "\126\122"
|
||||
elseif n<=32 then -- nonprint + space
|
||||
return "\126"..strchar(n+64)
|
||||
elseif n==94 then -- value separator
|
||||
return "\126\125"
|
||||
elseif n==126 then -- our own escape character
|
||||
return "\126\124"
|
||||
elseif n==127 then -- nonprint (DEL)
|
||||
return "\126\123"
|
||||
else
|
||||
assert(false) -- can't be reached if caller uses a sane regex
|
||||
end
|
||||
end
|
||||
|
||||
local function SerializeValue(v, res, nres)
|
||||
-- We use "^" as a value separator, followed by one byte for type indicator
|
||||
local t=type(v)
|
||||
|
||||
if t=="string" then -- ^S = string (escaped to remove nonprints, "^"s, etc)
|
||||
res[nres+1] = "^S"
|
||||
res[nres+2] = gsub(v,"[%c \94\126\127]", SerializeStringHelper)
|
||||
nres=nres+2
|
||||
|
||||
elseif t=="number" then -- ^N = number (just tostring()ed) or ^F (float components)
|
||||
local str = tostring(v)
|
||||
if tonumber(str)==v or str==serNaN or str==serInf or str==serNegInf then
|
||||
-- translates just fine, transmit as-is
|
||||
res[nres+1] = "^N"
|
||||
res[nres+2] = str
|
||||
nres=nres+2
|
||||
else
|
||||
local m,e = frexp(v)
|
||||
res[nres+1] = "^F"
|
||||
res[nres+2] = format("%.0f",m*2^53) -- force mantissa to become integer (it's originally 0.5--0.9999)
|
||||
res[nres+3] = "^f"
|
||||
res[nres+4] = tostring(e-53) -- adjust exponent to counteract mantissa manipulation
|
||||
nres=nres+4
|
||||
end
|
||||
|
||||
elseif t=="table" then -- ^T...^t = table (list of key,value pairs)
|
||||
nres=nres+1
|
||||
res[nres] = "^T"
|
||||
for k,v in pairs(v) do
|
||||
nres = SerializeValue(k, res, nres)
|
||||
nres = SerializeValue(v, res, nres)
|
||||
end
|
||||
nres=nres+1
|
||||
res[nres] = "^t"
|
||||
|
||||
elseif t=="boolean" then -- ^B = true, ^b = false
|
||||
nres=nres+1
|
||||
if v then
|
||||
res[nres] = "^B" -- true
|
||||
else
|
||||
res[nres] = "^b" -- false
|
||||
end
|
||||
|
||||
elseif t=="nil" then -- ^Z = nil (zero, "N" was taken :P)
|
||||
nres=nres+1
|
||||
res[nres] = "^Z"
|
||||
|
||||
else
|
||||
error(MAJOR..": Cannot serialize a value of type '"..t.."'") -- can't produce error on right level, this is wildly recursive
|
||||
end
|
||||
|
||||
return nres
|
||||
end
|
||||
|
||||
|
||||
|
||||
local serializeTbl = { "^1" } -- "^1" = Hi, I'm data serialized by AceSerializer protocol rev 1
|
||||
|
||||
--- Serialize the data passed into the function.
|
||||
-- Takes a list of values (strings, numbers, booleans, nils, tables)
|
||||
-- and returns it in serialized form (a string).\\
|
||||
-- May throw errors on invalid data types.
|
||||
-- @param ... List of values to serialize
|
||||
-- @return The data in its serialized form (string)
|
||||
function AceSerializer:Serialize(...)
|
||||
local nres = 1
|
||||
|
||||
for i=1,select("#", ...) do
|
||||
local v = select(i, ...)
|
||||
nres = SerializeValue(v, serializeTbl, nres)
|
||||
end
|
||||
|
||||
serializeTbl[nres+1] = "^^" -- "^^" = End of serialized data
|
||||
|
||||
return tconcat(serializeTbl, "", 1, nres+1)
|
||||
end
|
||||
|
||||
-- Deserialization functions
|
||||
local function DeserializeStringHelper(escape)
|
||||
if escape<"~\122" then
|
||||
return strchar(strbyte(escape,2,2)-64)
|
||||
elseif escape=="~\122" then -- v3 / ticket 115: special case encode since 30+64=94 ("^") - OOPS.
|
||||
return "\030"
|
||||
elseif escape=="~\123" then
|
||||
return "\127"
|
||||
elseif escape=="~\124" then
|
||||
return "\126"
|
||||
elseif escape=="~\125" then
|
||||
return "\94"
|
||||
end
|
||||
error("DeserializeStringHelper got called for '"..escape.."'?!?") -- can't be reached unless regex is screwed up
|
||||
end
|
||||
|
||||
local function DeserializeNumberHelper(number)
|
||||
if number == serNaN then
|
||||
return 0/0
|
||||
elseif number == serNegInf then
|
||||
return -1/0
|
||||
elseif number == serInf then
|
||||
return 1/0
|
||||
else
|
||||
return tonumber(number)
|
||||
end
|
||||
end
|
||||
|
||||
-- DeserializeValue: worker function for :Deserialize()
|
||||
-- It works in two modes:
|
||||
-- Main (top-level) mode: Deserialize a list of values and return them all
|
||||
-- Recursive (table) mode: Deserialize only a single value (_may_ of course be another table with lots of subvalues in it)
|
||||
--
|
||||
-- The function _always_ works recursively due to having to build a list of values to return
|
||||
--
|
||||
-- Callers are expected to pcall(DeserializeValue) to trap errors
|
||||
|
||||
local function DeserializeValue(iter,single,ctl,data)
|
||||
|
||||
if not single then
|
||||
ctl,data = iter()
|
||||
end
|
||||
|
||||
if not ctl then
|
||||
error("Supplied data misses AceSerializer terminator ('^^')")
|
||||
end
|
||||
|
||||
if ctl=="^^" then
|
||||
-- ignore extraneous data
|
||||
return
|
||||
end
|
||||
|
||||
local res
|
||||
|
||||
if ctl=="^S" then
|
||||
res = gsub(data, "~.", DeserializeStringHelper)
|
||||
elseif ctl=="^N" then
|
||||
res = DeserializeNumberHelper(data)
|
||||
if not res then
|
||||
error("Invalid serialized number: '"..tostring(data).."'")
|
||||
end
|
||||
elseif ctl=="^F" then -- ^F<mantissa>^f<exponent>
|
||||
local ctl2,e = iter()
|
||||
if ctl2~="^f" then
|
||||
error("Invalid serialized floating-point number, expected '^f', not '"..tostring(ctl2).."'")
|
||||
end
|
||||
local m=tonumber(data)
|
||||
e=tonumber(e)
|
||||
if not (m and e) then
|
||||
error("Invalid serialized floating-point number, expected mantissa and exponent, got '"..tostring(m).."' and '"..tostring(e).."'")
|
||||
end
|
||||
res = m*(2^e)
|
||||
elseif ctl=="^B" then -- yeah yeah ignore data portion
|
||||
res = true
|
||||
elseif ctl=="^b" then -- yeah yeah ignore data portion
|
||||
res = false
|
||||
elseif ctl=="^Z" then -- yeah yeah ignore data portion
|
||||
res = nil
|
||||
elseif ctl=="^T" then
|
||||
-- ignore ^T's data, future extensibility?
|
||||
res = {}
|
||||
local k,v
|
||||
while true do
|
||||
ctl,data = iter()
|
||||
if ctl=="^t" then break end -- ignore ^t's data
|
||||
k = DeserializeValue(iter,true,ctl,data)
|
||||
if k==nil then
|
||||
error("Invalid AceSerializer table format (no table end marker)")
|
||||
end
|
||||
ctl,data = iter()
|
||||
v = DeserializeValue(iter,true,ctl,data)
|
||||
if v==nil then
|
||||
error("Invalid AceSerializer table format (no table end marker)")
|
||||
end
|
||||
res[k]=v
|
||||
end
|
||||
else
|
||||
error("Invalid AceSerializer control code '"..ctl.."'")
|
||||
end
|
||||
|
||||
if not single then
|
||||
return res,DeserializeValue(iter)
|
||||
else
|
||||
return res
|
||||
end
|
||||
end
|
||||
|
||||
--- Deserializes the data into its original values.
|
||||
-- Accepts serialized data, ignoring all control characters and whitespace.
|
||||
-- @param str The serialized data (from :Serialize)
|
||||
-- @return true followed by a list of values, OR false followed by an error message
|
||||
function AceSerializer:Deserialize(str)
|
||||
str = gsub(str, "[%c ]", "") -- ignore all control characters; nice for embedding in email and stuff
|
||||
|
||||
local iter = gmatch(str, "(^.)([^^]*)") -- Any ^x followed by string of non-^
|
||||
local ctl,data = iter()
|
||||
if not ctl or ctl~="^1" then
|
||||
-- we purposefully ignore the data portion of the start code, it can be used as an extension mechanism
|
||||
return false, "Supplied data is not AceSerializer data (rev 1)"
|
||||
end
|
||||
|
||||
return pcall(DeserializeValue, iter)
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- Base library stuff
|
||||
----------------------------------------
|
||||
|
||||
AceSerializer.internals = { -- for test scripts
|
||||
SerializeValue = SerializeValue,
|
||||
SerializeStringHelper = SerializeStringHelper,
|
||||
}
|
||||
|
||||
local mixins = {
|
||||
"Serialize",
|
||||
"Deserialize",
|
||||
}
|
||||
|
||||
AceSerializer.embeds = AceSerializer.embeds or {}
|
||||
|
||||
function AceSerializer:Embed(target)
|
||||
for k, v in pairs(mixins) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeds[target] = true
|
||||
return target
|
||||
end
|
||||
|
||||
-- Update embeds
|
||||
for target, v in pairs(AceSerializer.embeds) do
|
||||
AceSerializer:Embed(target)
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="AceSerializer-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,327 @@
|
||||
--- **AceTimer-3.0** provides a central facility for registering timers.
|
||||
-- AceTimer supports one-shot timers and repeating timers. All timers are stored in an efficient
|
||||
-- data structure that allows easy dispatching and fast rescheduling. Timers can be registered
|
||||
-- or canceled at any time, even from within a running timer, without conflict or large overhead.\\
|
||||
-- AceTimer is currently limited to firing timers at a frequency of 0.01s.
|
||||
--
|
||||
-- All `:Schedule` functions will return a handle to the current timer, which you will need to store if you
|
||||
-- need to cancel the timer you just registered.
|
||||
--
|
||||
-- **AceTimer-3.0** can be embeded into your addon, either explicitly by calling AceTimer:Embed(MyAddon) or by
|
||||
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
|
||||
-- and can be accessed directly, without having to explicitly call AceTimer itself.\\
|
||||
-- It is recommended to embed AceTimer, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceTimer.
|
||||
-- @class file
|
||||
-- @name AceTimer-3.0
|
||||
-- @release $Id$
|
||||
|
||||
local MAJOR, MINOR = "AceTimer-3.0", 1017 -- Bump minor on changes
|
||||
local AceTimer, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceTimer then return end -- No upgrade needed
|
||||
AceTimer.frame = AceTimer.frame or CreateFrame("Frame", "AceTimer30Frame")
|
||||
AceTimer.activeTimers = AceTimer.activeTimers or {} -- Active timer list
|
||||
local activeTimers = AceTimer.activeTimers -- Upvalue our private data
|
||||
|
||||
-- Lua APIs
|
||||
local assert, loadstring, rawset, tconcat = assert, loadstring, rawset, table.concat
|
||||
local type, unpack, next, error, select = type, unpack, next, error, select
|
||||
-- WoW APIs
|
||||
local GetTime = GetTime
|
||||
|
||||
--[[
|
||||
xpcall safecall implementation
|
||||
]]
|
||||
local xpcall = xpcall
|
||||
|
||||
local function errorhandler(err)
|
||||
return geterrorhandler()(err)
|
||||
end
|
||||
|
||||
local function CreateDispatcher(argCount)
|
||||
local code = [[
|
||||
local xpcall, eh = ...
|
||||
local method, ARGS
|
||||
local function call() return method(ARGS) end
|
||||
|
||||
local function dispatch(func, ...)
|
||||
method = func
|
||||
if not method then return end
|
||||
ARGS = ...
|
||||
return xpcall(call, eh)
|
||||
end
|
||||
|
||||
return dispatch
|
||||
]]
|
||||
|
||||
local ARGS = {}
|
||||
for i = 1, argCount do ARGS[i] = "arg"..i end
|
||||
code = code:gsub("ARGS", tconcat(ARGS, ", "))
|
||||
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
|
||||
end
|
||||
|
||||
local Dispatchers = setmetatable({}, {__index=function(self, argCount)
|
||||
local dispatcher = CreateDispatcher(argCount)
|
||||
rawset(self, argCount, dispatcher)
|
||||
return dispatcher
|
||||
end})
|
||||
Dispatchers[0] = function(func)
|
||||
return xpcall(func, errorhandler)
|
||||
end
|
||||
|
||||
local function safecall(func, ...)
|
||||
return Dispatchers[select("#", ...)](func, ...)
|
||||
end
|
||||
|
||||
local function new(self, loop, func, delay, ...)
|
||||
if delay < 0.01 then
|
||||
delay = 0.01 -- Restrict to the lowest time
|
||||
end
|
||||
|
||||
local timer = {
|
||||
object = self,
|
||||
func = func,
|
||||
looping = loop,
|
||||
argsCount = select("#", ...),
|
||||
delay = delay,
|
||||
timeleft = delay,
|
||||
ends = GetTime() + delay,
|
||||
...
|
||||
}
|
||||
|
||||
activeTimers[timer] = timer
|
||||
|
||||
return timer
|
||||
end
|
||||
|
||||
--- Schedule a new one-shot timer.
|
||||
-- The timer will fire once in `delay` seconds, unless canceled before.
|
||||
-- @param callback Callback function for the timer pulse (funcref or method name).
|
||||
-- @param delay Delay for the timer, in seconds.
|
||||
-- @param ... An optional, unlimited amount of arguments to pass to the callback function.
|
||||
-- @usage
|
||||
-- MyAddOn = LibStub("AceAddon-3.0"):NewAddon("MyAddOn", "AceTimer-3.0")
|
||||
--
|
||||
-- function MyAddOn:OnEnable()
|
||||
-- self:ScheduleTimer("TimerFeedback", 5)
|
||||
-- end
|
||||
--
|
||||
-- function MyAddOn:TimerFeedback()
|
||||
-- print("5 seconds passed")
|
||||
-- end
|
||||
function AceTimer:ScheduleTimer(func, delay, ...)
|
||||
if not func or not delay then
|
||||
error(MAJOR..": ScheduleTimer(callback, delay, args...): 'callback' and 'delay' must have set values.", 2)
|
||||
end
|
||||
if type(func) == "string" then
|
||||
if type(self) ~= "table" then
|
||||
error(MAJOR..": ScheduleTimer(callback, delay, args...): 'self' - must be a table.", 2)
|
||||
elseif not self[func] then
|
||||
error(MAJOR..": ScheduleTimer(callback, delay, args...): Tried to register '"..func.."' as the callback, but it doesn't exist in the module.", 2)
|
||||
end
|
||||
end
|
||||
return new(self, nil, func, delay, ...)
|
||||
end
|
||||
|
||||
--- Schedule a repeating timer.
|
||||
-- The timer will fire every `delay` seconds, until canceled.
|
||||
-- @param callback Callback function for the timer pulse (funcref or method name).
|
||||
-- @param delay Delay for the timer, in seconds.
|
||||
-- @param ... An optional, unlimited amount of arguments to pass to the callback function.
|
||||
-- @usage
|
||||
-- MyAddOn = LibStub("AceAddon-3.0"):NewAddon("MyAddOn", "AceTimer-3.0")
|
||||
--
|
||||
-- function MyAddOn:OnEnable()
|
||||
-- self.timerCount = 0
|
||||
-- self.testTimer = self:ScheduleRepeatingTimer("TimerFeedback", 5)
|
||||
-- end
|
||||
--
|
||||
-- function MyAddOn:TimerFeedback()
|
||||
-- self.timerCount = self.timerCount + 1
|
||||
-- print(("%d seconds passed"):format(5 * self.timerCount))
|
||||
-- -- run 30 seconds in total
|
||||
-- if self.timerCount == 6 then
|
||||
-- self:CancelTimer(self.testTimer)
|
||||
-- end
|
||||
-- end
|
||||
function AceTimer:ScheduleRepeatingTimer(func, delay, ...)
|
||||
if not func or not delay then
|
||||
error(MAJOR..": ScheduleRepeatingTimer(callback, delay, args...): 'callback' and 'delay' must have set values.", 2)
|
||||
end
|
||||
if type(func) == "string" then
|
||||
if type(self) ~= "table" then
|
||||
error(MAJOR..": ScheduleRepeatingTimer(callback, delay, args...): 'self' - must be a table.", 2)
|
||||
elseif not self[func] then
|
||||
error(MAJOR..": ScheduleRepeatingTimer(callback, delay, args...): Tried to register '"..func.."' as the callback, but it doesn't exist in the module.", 2)
|
||||
end
|
||||
end
|
||||
return new(self, true, func, delay, ...)
|
||||
end
|
||||
|
||||
--- Cancels a timer with the given id, registered by the same addon object as used for `:ScheduleTimer`
|
||||
-- Both one-shot and repeating timers can be canceled with this function, as long as the `id` is valid
|
||||
-- and the timer has not fired yet or was canceled before.
|
||||
-- @param id The id of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer`
|
||||
function AceTimer:CancelTimer(id)
|
||||
local timer = activeTimers[id]
|
||||
|
||||
if not timer then
|
||||
return false
|
||||
else
|
||||
timer.cancelled = true
|
||||
activeTimers[id] = nil
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
--- Cancels all timers registered to the current addon object ('self')
|
||||
function AceTimer:CancelAllTimers()
|
||||
for k,v in next, activeTimers do
|
||||
if v.object == self then
|
||||
AceTimer.CancelTimer(self, k)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns the time left for a timer with the given id, registered by the current addon object ('self').
|
||||
-- This function will return 0 when the id is invalid.
|
||||
-- @param id The id of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer`
|
||||
-- @return The time left on the timer.
|
||||
function AceTimer:TimeLeft(id)
|
||||
local timer = activeTimers[id]
|
||||
if not timer then
|
||||
return 0
|
||||
else
|
||||
return timer.ends - GetTime()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Upgrading
|
||||
|
||||
-- Upgrade from old hash-bucket based timers to C_Timer.After timers.
|
||||
if oldminor and oldminor < 10 then
|
||||
-- disable old timer logic
|
||||
AceTimer.frame:SetScript("OnUpdate", nil)
|
||||
AceTimer.frame:SetScript("OnEvent", nil)
|
||||
AceTimer.frame:UnregisterAllEvents()
|
||||
-- convert timers
|
||||
for object,timers in next, AceTimer.selfs do
|
||||
for handle,timer in next, timers do
|
||||
if type(timer) == "table" and timer.callback then
|
||||
local newTimer
|
||||
if timer.delay then
|
||||
newTimer = AceTimer.ScheduleRepeatingTimer(timer.object, timer.callback, timer.delay, timer.arg)
|
||||
else
|
||||
newTimer = AceTimer.ScheduleTimer(timer.object, timer.callback, timer.when - GetTime(), timer.arg)
|
||||
end
|
||||
-- Use the old handle for old timers
|
||||
activeTimers[newTimer] = nil
|
||||
activeTimers[handle] = newTimer
|
||||
newTimer.handle = handle
|
||||
end
|
||||
end
|
||||
end
|
||||
AceTimer.selfs = nil
|
||||
AceTimer.hash = nil
|
||||
AceTimer.debug = nil
|
||||
elseif oldminor and oldminor < 17 then
|
||||
-- Upgrade from old animation based timers to C_Timer.After timers.
|
||||
AceTimer.inactiveTimers = nil
|
||||
local oldTimers = AceTimer.activeTimers
|
||||
-- Clear old timer table and update upvalue
|
||||
AceTimer.activeTimers = {}
|
||||
activeTimers = AceTimer.activeTimers
|
||||
for handle, timer in next, oldTimers do
|
||||
local newTimer
|
||||
-- Stop the old timer animation
|
||||
local duration, elapsed = timer:GetDuration(), timer:GetElapsed()
|
||||
timer:GetParent():Stop()
|
||||
if timer.looping then
|
||||
newTimer = AceTimer.ScheduleRepeatingTimer(timer.object, timer.func, duration, unpack(timer.args, 1, timer.argsCount))
|
||||
else
|
||||
newTimer = AceTimer.ScheduleTimer(timer.object, timer.func, duration - elapsed, unpack(timer.args, 1, timer.argsCount))
|
||||
end
|
||||
-- Use the old handle for old timers
|
||||
activeTimers[newTimer] = nil
|
||||
activeTimers[handle] = newTimer
|
||||
newTimer.handle = handle
|
||||
end
|
||||
|
||||
-- Migrate transitional handles
|
||||
if oldminor < 13 and AceTimer.hashCompatTable then
|
||||
for handle, id in next, AceTimer.hashCompatTable do
|
||||
local t = activeTimers[id]
|
||||
if t then
|
||||
activeTimers[id] = nil
|
||||
activeTimers[handle] = t
|
||||
t.handle = handle
|
||||
end
|
||||
end
|
||||
AceTimer.hashCompatTable = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Embed handling
|
||||
|
||||
AceTimer.embeds = AceTimer.embeds or {}
|
||||
|
||||
local mixins = {
|
||||
"ScheduleTimer", "ScheduleRepeatingTimer",
|
||||
"CancelTimer", "CancelAllTimers",
|
||||
"TimeLeft"
|
||||
}
|
||||
|
||||
function AceTimer:Embed(target)
|
||||
AceTimer.embeds[target] = true
|
||||
for _,v in next, mixins do
|
||||
target[v] = AceTimer[v]
|
||||
end
|
||||
return target
|
||||
end
|
||||
|
||||
-- AceTimer:OnEmbedDisable(target)
|
||||
-- target (object) - target object that AceTimer is embedded in.
|
||||
--
|
||||
-- cancel all timers registered for the object
|
||||
function AceTimer:OnEmbedDisable(target)
|
||||
target:CancelAllTimers()
|
||||
end
|
||||
|
||||
for addon in next, AceTimer.embeds do
|
||||
AceTimer:Embed(addon)
|
||||
end
|
||||
|
||||
AceTimer.frame:SetScript("OnUpdate", function(self, elapsed)
|
||||
for _, timer in next, activeTimers do
|
||||
if not timer.cancelled then
|
||||
if timer.timeleft > elapsed then
|
||||
timer.timeleft = timer.timeleft - elapsed
|
||||
else
|
||||
if type(timer.func) == "string" then
|
||||
-- We manually set the unpack count to prevent issues with an arg set that contains nil and ends with nil
|
||||
-- e.g. local t = {1, 2, nil, 3, nil} print(#t) will result in 2, instead of 5. This fixes said issue.
|
||||
safecall(timer.object[timer.func], timer.object, unpack(timer, 1, timer.argsCount))
|
||||
else
|
||||
safecall(timer.func, unpack(timer, 1, timer.argsCount))
|
||||
end
|
||||
|
||||
if timer.looping and not timer.cancelled then
|
||||
-- Compensate delay to get a perfect average delay, even if individual times don't match up perfectly
|
||||
-- due to fps differences
|
||||
local time = GetTime()
|
||||
local delay = timer.delay - (time - timer.ends)
|
||||
-- Ensure the delay doesn't go below the threshold
|
||||
if delay < 0.01 then delay = 0.01 end
|
||||
timer.ends = time + delay
|
||||
timer.timeleft = timer.delay
|
||||
else
|
||||
activeTimers[timer.handle or timer] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="AceTimer-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,238 @@
|
||||
--[[ $Id: CallbackHandler-1.0.lua 18 2014-10-16 02:52:20Z mikk $ ]]
|
||||
local MAJOR, MINOR = "CallbackHandler-1.0", 6
|
||||
local CallbackHandler = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not CallbackHandler then return end -- No upgrade needed
|
||||
|
||||
local meta = {__index = function(tbl, key) tbl[key] = {} return tbl[key] end}
|
||||
|
||||
-- Lua APIs
|
||||
local tconcat = table.concat
|
||||
local assert, error, loadstring = assert, error, loadstring
|
||||
local setmetatable, rawset, rawget = setmetatable, rawset, rawget
|
||||
local next, select, pairs, type, tostring = next, select, pairs, type, tostring
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: geterrorhandler
|
||||
|
||||
local xpcall = xpcall
|
||||
|
||||
local function errorhandler(err)
|
||||
return geterrorhandler()(err)
|
||||
end
|
||||
|
||||
local function CreateDispatcher(argCount)
|
||||
local code = [[
|
||||
local next, xpcall, eh = ...
|
||||
|
||||
local method, ARGS
|
||||
local function call() method(ARGS) end
|
||||
|
||||
local function dispatch(handlers, ...)
|
||||
local index
|
||||
index, method = next(handlers)
|
||||
if not method then return end
|
||||
local OLD_ARGS = ARGS
|
||||
ARGS = ...
|
||||
repeat
|
||||
xpcall(call, eh)
|
||||
index, method = next(handlers, index)
|
||||
until not method
|
||||
ARGS = OLD_ARGS
|
||||
end
|
||||
|
||||
return dispatch
|
||||
]]
|
||||
|
||||
local ARGS, OLD_ARGS = {}, {}
|
||||
for i = 1, argCount do ARGS[i], OLD_ARGS[i] = "arg"..i, "old_arg"..i end
|
||||
code = code:gsub("OLD_ARGS", tconcat(OLD_ARGS, ", ")):gsub("ARGS", tconcat(ARGS, ", "))
|
||||
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(next, xpcall, errorhandler)
|
||||
end
|
||||
|
||||
local Dispatchers = setmetatable({}, {__index=function(self, argCount)
|
||||
local dispatcher = CreateDispatcher(argCount)
|
||||
rawset(self, argCount, dispatcher)
|
||||
return dispatcher
|
||||
end})
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
-- CallbackHandler:New
|
||||
--
|
||||
-- target - target object to embed public APIs in
|
||||
-- RegisterName - name of the callback registration API, default "RegisterCallback"
|
||||
-- UnregisterName - name of the callback unregistration API, default "UnregisterCallback"
|
||||
-- UnregisterAllName - name of the API to unregister all callbacks, default "UnregisterAllCallbacks". false == don't publish this API.
|
||||
|
||||
function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAllName)
|
||||
|
||||
RegisterName = RegisterName or "RegisterCallback"
|
||||
UnregisterName = UnregisterName or "UnregisterCallback"
|
||||
if UnregisterAllName==nil then -- false is used to indicate "don't want this method"
|
||||
UnregisterAllName = "UnregisterAllCallbacks"
|
||||
end
|
||||
|
||||
-- we declare all objects and exported APIs inside this closure to quickly gain access
|
||||
-- to e.g. function names, the "target" parameter, etc
|
||||
|
||||
|
||||
-- Create the registry object
|
||||
local events = setmetatable({}, meta)
|
||||
local registry = { recurse=0, events=events }
|
||||
|
||||
-- registry:Fire() - fires the given event/message into the registry
|
||||
function registry:Fire(eventname, ...)
|
||||
if not rawget(events, eventname) or not next(events[eventname]) then return end
|
||||
local oldrecurse = registry.recurse
|
||||
registry.recurse = oldrecurse + 1
|
||||
|
||||
Dispatchers[select('#', ...) + 1](events[eventname], eventname, ...)
|
||||
|
||||
registry.recurse = oldrecurse
|
||||
|
||||
if registry.insertQueue and oldrecurse==0 then
|
||||
-- Something in one of our callbacks wanted to register more callbacks; they got queued
|
||||
for eventname,callbacks in pairs(registry.insertQueue) do
|
||||
local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten.
|
||||
for self,func in pairs(callbacks) do
|
||||
events[eventname][self] = func
|
||||
-- fire OnUsed callback?
|
||||
if first and registry.OnUsed then
|
||||
registry.OnUsed(registry, target, eventname)
|
||||
first = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
registry.insertQueue = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Registration of a callback, handles:
|
||||
-- self["method"], leads to self["method"](self, ...)
|
||||
-- self with function ref, leads to functionref(...)
|
||||
-- "addonId" (instead of self) with function ref, leads to functionref(...)
|
||||
-- all with an optional arg, which, if present, gets passed as first argument (after self if present)
|
||||
target[RegisterName] = function(self, eventname, method, ... --[[actually just a single arg]])
|
||||
if type(eventname) ~= "string" then
|
||||
error("Usage: "..RegisterName.."(eventname, method[, arg]): 'eventname' - string expected.", 2)
|
||||
end
|
||||
|
||||
method = method or eventname
|
||||
|
||||
local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten.
|
||||
|
||||
if type(method) ~= "string" and type(method) ~= "function" then
|
||||
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - string or function expected.", 2)
|
||||
end
|
||||
|
||||
local regfunc
|
||||
|
||||
if type(method) == "string" then
|
||||
-- self["method"] calling style
|
||||
if type(self) ~= "table" then
|
||||
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): self was not a table?", 2)
|
||||
elseif self==target then
|
||||
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): do not use Library:"..RegisterName.."(), use your own 'self'", 2)
|
||||
elseif type(self[method]) ~= "function" then
|
||||
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - method '"..tostring(method).."' not found on self.", 2)
|
||||
end
|
||||
|
||||
if select("#",...)>=1 then -- this is not the same as testing for arg==nil!
|
||||
local arg=select(1,...)
|
||||
regfunc = function(...) self[method](self,arg,...) end
|
||||
else
|
||||
regfunc = function(...) self[method](self,...) end
|
||||
end
|
||||
else
|
||||
-- function ref with self=object or self="addonId" or self=thread
|
||||
if type(self)~="table" and type(self)~="string" and type(self)~="thread" then
|
||||
error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string or thread expected.", 2)
|
||||
end
|
||||
|
||||
if select("#",...)>=1 then -- this is not the same as testing for arg==nil!
|
||||
local arg=select(1,...)
|
||||
regfunc = function(...) method(arg,...) end
|
||||
else
|
||||
regfunc = method
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if events[eventname][self] or registry.recurse<1 then
|
||||
-- if registry.recurse<1 then
|
||||
-- we're overwriting an existing entry, or not currently recursing. just set it.
|
||||
events[eventname][self] = regfunc
|
||||
-- fire OnUsed callback?
|
||||
if registry.OnUsed and first then
|
||||
registry.OnUsed(registry, target, eventname)
|
||||
end
|
||||
else
|
||||
-- we're currently processing a callback in this registry, so delay the registration of this new entry!
|
||||
-- yes, we're a bit wasteful on garbage, but this is a fringe case, so we're picking low implementation overhead over garbage efficiency
|
||||
registry.insertQueue = registry.insertQueue or setmetatable({},meta)
|
||||
registry.insertQueue[eventname][self] = regfunc
|
||||
end
|
||||
end
|
||||
|
||||
-- Unregister a callback
|
||||
target[UnregisterName] = function(self, eventname)
|
||||
if not self or self==target then
|
||||
error("Usage: "..UnregisterName.."(eventname): bad 'self'", 2)
|
||||
end
|
||||
if type(eventname) ~= "string" then
|
||||
error("Usage: "..UnregisterName.."(eventname): 'eventname' - string expected.", 2)
|
||||
end
|
||||
if rawget(events, eventname) and events[eventname][self] then
|
||||
events[eventname][self] = nil
|
||||
-- Fire OnUnused callback?
|
||||
if registry.OnUnused and not next(events[eventname]) then
|
||||
registry.OnUnused(registry, target, eventname)
|
||||
end
|
||||
end
|
||||
if registry.insertQueue and rawget(registry.insertQueue, eventname) and registry.insertQueue[eventname][self] then
|
||||
registry.insertQueue[eventname][self] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- OPTIONAL: Unregister all callbacks for given selfs/addonIds
|
||||
if UnregisterAllName then
|
||||
target[UnregisterAllName] = function(...)
|
||||
if select("#",...)<1 then
|
||||
error("Usage: "..UnregisterAllName.."([whatFor]): missing 'self' or \"addonId\" to unregister events for.", 2)
|
||||
end
|
||||
if select("#",...)==1 and ...==target then
|
||||
error("Usage: "..UnregisterAllName.."([whatFor]): supply a meaningful 'self' or \"addonId\"", 2)
|
||||
end
|
||||
|
||||
|
||||
for i=1,select("#",...) do
|
||||
local self = select(i,...)
|
||||
if registry.insertQueue then
|
||||
for eventname, callbacks in pairs(registry.insertQueue) do
|
||||
if callbacks[self] then
|
||||
callbacks[self] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
for eventname, callbacks in pairs(events) do
|
||||
if callbacks[self] then
|
||||
callbacks[self] = nil
|
||||
-- Fire OnUnused callback?
|
||||
if registry.OnUnused and not next(callbacks) then
|
||||
registry.OnUnused(registry, target, eventname)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return registry
|
||||
end
|
||||
|
||||
|
||||
-- CallbackHandler purposefully does NOT do explicit embedding. Nor does it
|
||||
-- try to upgrade old implicit embeds since the system is selfcontained and
|
||||
-- relies on closures to work.
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
-- $Id: LibStub.lua 103 2014-10-16 03:02:50Z mikk $
|
||||
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/addons/libstub/ for more info
|
||||
-- LibStub is hereby placed in the Public Domain
|
||||
-- Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
|
||||
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
|
||||
local LibStub = _G[LIBSTUB_MAJOR]
|
||||
|
||||
-- Check to see is this version of the stub is obsolete
|
||||
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
|
||||
LibStub = LibStub or {libs = {}, minors = {} }
|
||||
_G[LIBSTUB_MAJOR] = LibStub
|
||||
LibStub.minor = LIBSTUB_MINOR
|
||||
|
||||
-- LibStub:NewLibrary(major, minor)
|
||||
-- major (string) - the major version of the library
|
||||
-- minor (string or number ) - the minor version of the library
|
||||
--
|
||||
-- returns nil if a newer or same version of the lib is already present
|
||||
-- returns empty library object or old library object if upgrade is needed
|
||||
function LibStub:NewLibrary(major, minor)
|
||||
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
|
||||
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
|
||||
|
||||
local oldminor = self.minors[major]
|
||||
if oldminor and oldminor >= minor then return nil end
|
||||
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
|
||||
return self.libs[major], oldminor
|
||||
end
|
||||
|
||||
-- LibStub:GetLibrary(major, [silent])
|
||||
-- major (string) - the major version of the library
|
||||
-- silent (boolean) - if true, library is optional, silently return nil if its not found
|
||||
--
|
||||
-- throws an error if the library can not be found (except silent is set)
|
||||
-- returns the library object if found
|
||||
function LibStub:GetLibrary(major, silent)
|
||||
if not self.libs[major] and not silent then
|
||||
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
|
||||
end
|
||||
return self.libs[major], self.minors[major]
|
||||
end
|
||||
|
||||
-- LibStub:IterateLibraries()
|
||||
--
|
||||
-- Returns an iterator for the currently registered libraries
|
||||
function LibStub:IterateLibraries()
|
||||
return pairs(self.libs)
|
||||
end
|
||||
|
||||
setmetatable(LibStub, { __call = LibStub.GetLibrary })
|
||||
end
|
||||
@@ -0,0 +1,542 @@
|
||||
--[[
|
||||
API:
|
||||
* RegisterCallback(addon, callback)
|
||||
`callback` is called whenever some heal state (new heal/ heal stop/ heal delay) changes.
|
||||
callback`'s arguments will be all units affected by the change in heal state, e.g.,
|
||||
`callback("Tankguy", "Dpsguy")`.
|
||||
|
||||
* UnregisterCallback(addon)
|
||||
Remove all callbacks registered by `addon`.
|
||||
|
||||
* UnitGetIncomingHeals(unit[, healer])
|
||||
Return predicted incoming heals on unit. If `healer`, only predict incoming heals from healer.
|
||||
]]
|
||||
local ADDON_NAME = "HealPredict"
|
||||
|
||||
-- Wow API
|
||||
local CheckInteractDistance = CheckInteractDistance
|
||||
local CreateFrame = CreateFrame
|
||||
local GetInventoryItemLink = GetInventoryItemLink
|
||||
local GetLocale = GetLocale
|
||||
local GetNumRaidMembers = GetNumRaidMembers
|
||||
local GetSpellInfo = GetSpellInfo
|
||||
local GetTime = GetTime
|
||||
local SendAddonMessage = SendAddonMessage
|
||||
local strjoin = strjoin
|
||||
local strsplit = strsplit
|
||||
local UIParent = UIParent
|
||||
local UnitBuff = UnitBuff
|
||||
local UnitCanAssist =UnitCanAssist
|
||||
local UnitCastingInfo = UnitCastingInfo
|
||||
local UnitChannelInfo = UnitChannelInfo
|
||||
local UnitHealth = UnitHealth
|
||||
local UnitHealthMax = UnitHealthMax
|
||||
local UnitInRaid = UnitInRaid
|
||||
local UnitName = UnitName
|
||||
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
|
||||
|
||||
-- Addon message constants:
|
||||
local HEALSTOP = "HealStop"
|
||||
local HEALDELAY = "HealDelay"
|
||||
local HEAL = "Heal"
|
||||
local SEP = "/"
|
||||
|
||||
-- Localize spell names:
|
||||
local BEACON_OF_LIGHT
|
||||
do
|
||||
local locales = {
|
||||
deDE = "Flamme des Glaubens",
|
||||
enUS = "Beacon of Light",
|
||||
esES = "Señal de la Luz",
|
||||
esMX = "Señal de la Luz",
|
||||
frFR = "Guide de lumière",
|
||||
itIT = "Faro di Luce",
|
||||
koKR = "빛의 봉화",
|
||||
ptBR = "Foco de Luz",
|
||||
ruRU = "Частица Света",
|
||||
zhCN = "圣光道标",
|
||||
zhTW = "聖光信標",
|
||||
}
|
||||
|
||||
BEACON_OF_LIGHT = locales[GetLocale()] or locales.enUS
|
||||
end
|
||||
|
||||
local CHAIN_HEAL
|
||||
do
|
||||
local locales = {
|
||||
deDE = "Kettenheilung",
|
||||
enUS = "Chain Heal",
|
||||
esES = "Sanación en cadena",
|
||||
esMX = "Sanación en cadena",
|
||||
frFR = "Salve de guérison",
|
||||
itIT = "Catena di Guarigione",
|
||||
koKR = "연쇄 치유",
|
||||
ptBR = "Cura Encadeada",
|
||||
ruRU = "Цепное исцеление",
|
||||
zhCN = "治疗链",
|
||||
zhTW = "治療鍊",
|
||||
}
|
||||
|
||||
CHAIN_HEAL = locales[GetLocale()] or locales.enUS
|
||||
end
|
||||
|
||||
local PRAYER_OF_HEALING
|
||||
do
|
||||
local locales = {
|
||||
deDE = "Gebet der Heilung",
|
||||
enUS = "Prayer of Healing",
|
||||
esES = "Rezo de curación",
|
||||
esMX = "Rezo de sanación",
|
||||
frFR = "Prière de soins",
|
||||
itIT = "Preghiera di Cura",
|
||||
koKR = "치유의 기원",
|
||||
ptBR = "Prece de Cura",
|
||||
ruRU = "Молитва исцеления",
|
||||
zhCN = "治疗祷言",
|
||||
zhTW = "治療禱言",
|
||||
}
|
||||
|
||||
PRAYER_OF_HEALING = locales[GetLocale()] or locales.enUS
|
||||
end
|
||||
|
||||
local PRAYER_OF_PRESERVATION = "Prayer of Preservation"
|
||||
|
||||
local TRANQUILITY
|
||||
do
|
||||
local locales = {
|
||||
deDE = "Gelassenheit",
|
||||
enUS = "Tranquility",
|
||||
esES = "Tranquilidad",
|
||||
esMX = "Tranquilidad",
|
||||
frFR = "Tranquillité",
|
||||
itIT = "Tranquillità",
|
||||
koKR = "평온",
|
||||
ptBR = "Tranquilidade",
|
||||
ruRU = "Спокойствие",
|
||||
zhCN = "宁静",
|
||||
zhTW = "寧靜",
|
||||
}
|
||||
|
||||
TRANQUILITY = locales[GetLocale()] or locales.enUS
|
||||
end
|
||||
|
||||
local SMART_HEALS = { }
|
||||
SMART_HEALS[TRANQUILITY] = 5
|
||||
SMART_HEALS[PRAYER_OF_PRESERVATION] = 5
|
||||
SMART_HEALS[CHAIN_HEAL] = 3
|
||||
|
||||
-- Addon locals
|
||||
local player = UnitName("player")
|
||||
local heals, callbacks, cache, gear_string = { }, { }, { }, ""
|
||||
local is_healing, beacon_info, current_target
|
||||
|
||||
-- API functions
|
||||
local healpredict = CreateFrame("Frame")
|
||||
function healpredict.UnitGetIncomingHeals(unit, healer)
|
||||
if UnitIsDeadOrGhost(unit) then return 0 end
|
||||
|
||||
local name = UnitName(unit)
|
||||
|
||||
if not heals[name] then
|
||||
return 0
|
||||
end
|
||||
|
||||
local sumheal, time = 0, GetTime()
|
||||
|
||||
for sender, amount in pairs(heals[name]) do
|
||||
if amount[2] <= time then
|
||||
heals[name][sender] = nil
|
||||
elseif not healer or sender == healer then
|
||||
sumheal = sumheal + amount[1]
|
||||
end
|
||||
end
|
||||
|
||||
return sumheal
|
||||
end
|
||||
|
||||
function healpredict.RegisterCallback(addon, callback)
|
||||
callbacks[addon] = callback
|
||||
end
|
||||
|
||||
function healpredict.UnregisterCallback(addon)
|
||||
callbacks[addon] = nil
|
||||
end
|
||||
|
||||
-- Private functions
|
||||
local function UpdateCache(spell, heal)
|
||||
--[[
|
||||
cache total of all heals and number of casts
|
||||
for calculating a rolling average of the heal
|
||||
]]
|
||||
local heal = tonumber(heal)
|
||||
|
||||
if not cache[spell] then
|
||||
cache[spell] = {heal, 1}
|
||||
else
|
||||
cache[spell][1] = cache[spell][1] + heal
|
||||
cache[spell][2] = cache[spell][2] + 1
|
||||
end
|
||||
end
|
||||
|
||||
local function handleCallbacks(...)
|
||||
for _, v in pairs(callbacks) do
|
||||
v(...)
|
||||
end
|
||||
end
|
||||
|
||||
local function Heal(sender, target, amount, duration)
|
||||
heals[target] = heals[target] or { }
|
||||
heals[target][sender] = {amount, GetTime() + duration / 1000}
|
||||
|
||||
handleCallbacks(target)
|
||||
end
|
||||
|
||||
local function HealStop(sender)
|
||||
local affected = { }
|
||||
for target, _ in pairs(heals) do
|
||||
for tsender in pairs(heals[target]) do
|
||||
if sender == tsender then
|
||||
heals[target][tsender] = nil
|
||||
table.insert(affected, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
handleCallbacks(unpack(affected))
|
||||
end
|
||||
|
||||
local function HealDelay(sender, delay)
|
||||
if type(delay) ~= "string" then
|
||||
local delay = delay / 1000
|
||||
local affected = { }
|
||||
for target, _ in pairs(heals) do
|
||||
for tsender, amount in pairs(heals[target]) do
|
||||
if sender == tsender then
|
||||
amount[2] = amount[2] + delay
|
||||
table.insert(affected, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
handleCallbacks(unpack(affected))
|
||||
end
|
||||
end
|
||||
|
||||
local function SendHealMsg(msg)
|
||||
SendAddonMessage(ADDON_NAME, msg, "RAID")
|
||||
SendAddonMessage(ADDON_NAME, msg, "BATTLEGROUND")
|
||||
end
|
||||
|
||||
local function max(targets)
|
||||
local currentmax = -1
|
||||
local raidname
|
||||
|
||||
for name, pct in pairs(targets) do
|
||||
if pct > currentmax then
|
||||
currentmax = pct
|
||||
raidname = name
|
||||
end
|
||||
end
|
||||
|
||||
return raidname
|
||||
end
|
||||
|
||||
local function BeaconTarget()
|
||||
if beacon_info then
|
||||
local beacon_target, endtime = unpack(beacon_info)
|
||||
if endtime > GetTime() then
|
||||
beacon_info = nil
|
||||
else
|
||||
return beacon_target
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function GroupHeal(amount, casttime)
|
||||
local partyN, partyname, beacon_found
|
||||
local beacon_target = BeaconTarget()
|
||||
|
||||
for i=1,4 do
|
||||
partyN = "party"..i
|
||||
|
||||
if CheckInteractDistance(partyN, 4) then
|
||||
partyname = (UnitName(partyN))
|
||||
if beacon_target and partyname == beacon_target then
|
||||
beacon_found = true
|
||||
Heal(player, partyname, amount * 1.4, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, partyname, amount * 1.4, casttime))
|
||||
elseif partyname then
|
||||
Heal(player, partyname, amount, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, partyname, amount, casttime))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if beacon_target and not beacon_found then
|
||||
Heal(player, beacon_target, amount * .4, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, beacon_target, amount * .4, casttime))
|
||||
end
|
||||
|
||||
Heal(player, player, amount, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, player, amount, casttime))
|
||||
end
|
||||
|
||||
local function SmartHeal(amount, casttime, n)
|
||||
if not UnitInRaid("player") then
|
||||
return GroupHeal(amount, casttime)
|
||||
end
|
||||
|
||||
local beacon_target = BeaconTarget()
|
||||
local beacon_found
|
||||
|
||||
local healthpct, currentmax
|
||||
local pcts = { }
|
||||
local raidN, raidname
|
||||
|
||||
for i=1,GetNumRaidMembers() do
|
||||
raidN = "raid"..i
|
||||
|
||||
if not UnitIsDeadOrGhost(raidN) and CheckInteractDistance(raidN, 4) then
|
||||
raidname = (UnitName(raidN))
|
||||
healthpct = UnitHealth(raidN) / UnitHealthMax(raidname)
|
||||
|
||||
if #pcts < n then
|
||||
pcts[raidname] = healthpct
|
||||
|
||||
if not currentmax or healthpct > pcts[currentmax] then
|
||||
currentmax = raidname
|
||||
end
|
||||
|
||||
elseif healthpct < pcts[currentmax] then
|
||||
pcts[currentmax] = nil
|
||||
pcts[raidname] = healthpct
|
||||
currentmax = max(pcts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for target, _ in pairs(pcts) do
|
||||
if beacon_target and target == beacon_target then
|
||||
beacon_found = true
|
||||
Heal(player, target, amount * 1.4, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, target, amount * 1.4, casttime))
|
||||
else
|
||||
Heal(player, target, amount, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, target, amount, casttime))
|
||||
end
|
||||
end
|
||||
|
||||
if beacon_target and not beacon_found then
|
||||
Heal(player, beacon_target, amount * .4, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, beacon_target, amount * .4, casttime))
|
||||
end
|
||||
end
|
||||
|
||||
local function UnitByName(name)
|
||||
if name == player then
|
||||
return "player"
|
||||
end
|
||||
|
||||
local unit
|
||||
|
||||
if UnitInRaid("player") then
|
||||
for i=1,GetNumRaidMembers() do
|
||||
unit = "raid"..i
|
||||
|
||||
if (UnitName(unit)) == name then
|
||||
return unit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for i=1,4 do
|
||||
unit = "party"..i
|
||||
|
||||
if (UnitName(unit)) == name then
|
||||
return unit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Message passing
|
||||
healpredict:RegisterEvent("CHAT_MSG_ADDON")
|
||||
healpredict:SetScript("OnEvent", function(_, _, prefix, msg, _, sender)
|
||||
if prefix == ADDON_NAME then
|
||||
local command, target_or_delay, amount, casttime = strsplit(SEP, msg)
|
||||
if command == HEALSTOP then
|
||||
HealStop(sender)
|
||||
elseif command == HEAL then
|
||||
Heal(sender, target_or_delay, amount, casttime)
|
||||
elseif command == HEALDELAY then
|
||||
HealDelay(sender, target_or_delay)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Reset cache on skill or inventory change
|
||||
local resetcache = CreateFrame("Frame")
|
||||
resetcache:RegisterEvent("SKILL_LINES_CHANGED")
|
||||
resetcache:RegisterEvent("UNIT_INVENTORY_CHANGED")
|
||||
resetcache:SetScript("OnEvent", function(_, event, player)
|
||||
if player ~= "player" then
|
||||
return
|
||||
end
|
||||
|
||||
if event == "UNIT_INVENTORY_CHANGED" then
|
||||
local gear = ""
|
||||
for id = 1, 18 do
|
||||
gear = gear .. (GetInventoryItemLink("player",id) or "")
|
||||
end
|
||||
|
||||
if gear == gear_string then
|
||||
return
|
||||
end
|
||||
|
||||
gear_string = gear
|
||||
end
|
||||
|
||||
-- reset cache
|
||||
cache = { }
|
||||
end)
|
||||
|
||||
--Event handling
|
||||
----------------
|
||||
local eventhandler = CreateFrame("Frame", ADDON_NAME .. "EventHandler", UIParent)
|
||||
|
||||
eventhandler:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
|
||||
function eventhandler.COMBAT_LOG_EVENT_UNFILTERED(_, subevent, _, sourcename, _, _, destname, _, spellid, spellname, _, amount)
|
||||
if sourcename ~= player then return end
|
||||
|
||||
if subevent == "SPELL_HEAL" then
|
||||
local _, rank = GetSpellInfo(spellid)
|
||||
local spellrank = spellname..(rank or "")
|
||||
UpdateCache(spellrank, amount)
|
||||
|
||||
if spellname == TRANQUILITY then
|
||||
-- Need to re-acquire tranq targets
|
||||
HealStop(player)
|
||||
SendHealMsg(HEALSTOP)
|
||||
|
||||
local _, _, _, _, starttime, endtime = UnitChannelInfo("player")
|
||||
if starttime ~= nil and endtime ~= nil then
|
||||
local casttime = endtime - starttime
|
||||
|
||||
local total, casts = unpack(cache[spellrank])
|
||||
local amount = total / casts
|
||||
|
||||
SmartHeal(amount, casttime, 5)
|
||||
is_healing = true
|
||||
end
|
||||
end
|
||||
elseif spellname == BEACON_OF_LIGHT then
|
||||
if subevent == "SPELL_AURA_APPLIED" then
|
||||
local unit = UnitByName(destname)
|
||||
|
||||
if not unit then
|
||||
return
|
||||
end
|
||||
|
||||
for i=1,40 do
|
||||
local buff, _, _, _, _, endtime = UnitBuff(unit, i)
|
||||
if buff == BEACON_OF_LIGHT then
|
||||
beacon_info = {destname, endtime}
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
elseif subevent == "SPELL_AURA_REMOVED" then
|
||||
beacon_info = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
eventhandler:RegisterEvent("UNIT_SPELLCAST_SENT")
|
||||
function eventhandler.UNIT_SPELLCAST_SENT(unit, _, _, target)
|
||||
if unit == "player" then
|
||||
if target == "" then
|
||||
current_target = UnitCanAssist("player", "target") and UnitName("target") or player
|
||||
else
|
||||
current_target = target
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
eventhandler:RegisterEvent("UNIT_SPELLCAST_START")
|
||||
function eventhandler.UNIT_SPELLCAST_START(unit)
|
||||
if unit ~= "player" then return end
|
||||
|
||||
local spell, rank, _, _, starttime, endtime = UnitCastingInfo("player")
|
||||
if not spell then
|
||||
spell, rank, _, _, starttime, endtime = UnitChannelInfo("player")
|
||||
end
|
||||
local casttime = endtime - starttime
|
||||
local spellrank = spell..(rank or "")
|
||||
|
||||
if cache[spellrank] then
|
||||
local total, casts = unpack(cache[spellrank])
|
||||
local amount = total / casts
|
||||
|
||||
if spell == PRAYER_OF_HEALING then
|
||||
GroupHeal(amount, casttime)
|
||||
elseif SMART_HEALS[spell] then
|
||||
SmartHeal(amount, casttime, SMART_HEALS[spell])
|
||||
else
|
||||
local beacon_target = BeaconTarget()
|
||||
|
||||
if beacon_target then
|
||||
if beacon_target ~= current_target then
|
||||
Heal(player, current_target, amount, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, current_target, amount, casttime))
|
||||
|
||||
Heal(player, beacon_target, amount * .4, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, beacon_target, amount * .4, casttime))
|
||||
else
|
||||
Heal(player, beacon_target, amount * 1.4, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, beacon_target, amount * 1.4, casttime))
|
||||
end
|
||||
else
|
||||
Heal(player, current_target, amount, casttime)
|
||||
SendHealMsg(strjoin(SEP, HEAL, current_target, amount, casttime))
|
||||
end
|
||||
end
|
||||
|
||||
is_healing = true
|
||||
end
|
||||
end
|
||||
|
||||
eventhandler:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
|
||||
eventhandler.UNIT_SPELLCAST_CHANNEL_START = eventhandler.UNIT_SPELLCAST_START
|
||||
|
||||
eventhandler:RegisterEvent("UNIT_SPELLCAST_FAILED")
|
||||
function eventhandler.UNIT_SPELLCAST_FAILED(unit)
|
||||
if is_healing and unit == "player" then
|
||||
HealStop(player)
|
||||
SendHealMsg(HEALSTOP)
|
||||
is_healing = nil
|
||||
end
|
||||
end
|
||||
|
||||
eventhandler:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
|
||||
eventhandler.UNIT_SPELLCAST_INTERRUPTED = eventhandler.UNIT_SPELLCAST_FAILED
|
||||
|
||||
eventhandler:RegisterEvent("UNIT_SPELLCAST_STOP")
|
||||
eventhandler.UNIT_SPELLCAST_STOP = eventhandler.UNIT_SPELLCAST_FAILED
|
||||
|
||||
eventhandler:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
|
||||
eventhandler.UNIT_SPELLCAST_CHANNEL_STOP = eventhandler.UNIT_SPELLCAST_FAILED
|
||||
|
||||
eventhandler:RegisterEvent("UNIT_SPELLCAST_DELAYED")
|
||||
function eventhandler.UNIT_SPELLCAST_DELAYED(unit, delay)
|
||||
if is_healing and unit == "player" then
|
||||
HealDelay(player, delay)
|
||||
SendHealMsg(strjoin(SEP, HEALDELAY, delay))
|
||||
end
|
||||
end
|
||||
|
||||
eventhandler:SetScript("OnEvent", function(_, event, ...)
|
||||
local handler = eventhandler[event]
|
||||
if handler then
|
||||
handler(...)
|
||||
end
|
||||
end)
|
||||
|
||||
_G[ADDON_NAME] = healpredict
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="LibAuraInfo-1.0.lua" />
|
||||
<Script file="spellIdData.lua" />
|
||||
<!--@debug@
|
||||
<Script file="otherSpellIDData.lua" />
|
||||
@end-debug@-->
|
||||
</Ui>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,164 @@
|
||||
--[[
|
||||
Name: LibBase64-1.0
|
||||
Author(s): ckknight (ckknight@gmail.com)
|
||||
Website: http://www.wowace.com/projects/libbase64-1-0/
|
||||
Description: A library to encode and decode Base64 strings
|
||||
License: MIT
|
||||
]]
|
||||
|
||||
local MAJOR, MINOR = 'LibBase64-1.0-ElvUI', 2
|
||||
local LibBase64 = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
if not LibBase64 then return end
|
||||
|
||||
local wipe, type, error, format, strsub, strchar, strbyte, tconcat = wipe, type, error, format, strsub, strchar, strbyte, table.concat
|
||||
local _chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||
local byteToNum, numToChar = {}, {}
|
||||
for i = 1, #_chars do
|
||||
numToChar[i - 1] = strsub(_chars, i, i)
|
||||
byteToNum[strbyte(_chars, i)] = i - 1
|
||||
end
|
||||
|
||||
local t = {}
|
||||
local equals_byte = strbyte("=")
|
||||
local whitespace = {
|
||||
[strbyte(" ")] = true,
|
||||
[strbyte("\t")] = true,
|
||||
[strbyte("\n")] = true,
|
||||
[strbyte("\r")] = true,
|
||||
}
|
||||
|
||||
--- Encode a normal bytestring into a Base64-encoded string
|
||||
-- @param text a bytestring, can be binary data
|
||||
-- @param maxLineLength This should be a multiple of 4, greater than 0 or nil. If non-nil, it will break up the output into lines no longer than the given number of characters. 76 is recommended.
|
||||
-- @param lineEnding a string to end each line with. This is "\r\n" by default.
|
||||
-- @usage LibBase64.Encode("Hello, how are you doing today?") == "SGVsbG8sIGhvdyBhcmUgeW91IGRvaW5nIHRvZGF5Pw=="
|
||||
-- @return a Base64-encoded string
|
||||
function LibBase64:Encode(text, maxLineLength, lineEnding)
|
||||
if type(text) ~= "string" then
|
||||
error(format("Bad argument #1 to `Encode'. Expected string, got %q", type(text)), 2)
|
||||
end
|
||||
|
||||
if maxLineLength then
|
||||
if type(maxLineLength) ~= "number" then
|
||||
error(format("Bad argument #2 to `Encode'. Expected number or nil, got %q", type(maxLineLength)), 2)
|
||||
elseif (maxLineLength % 4) ~= 0 then
|
||||
error(format("Bad argument #2 to `Encode'. Expected a multiple of 4, got %s", maxLineLength), 2)
|
||||
elseif maxLineLength <= 0 then
|
||||
error(format("Bad argument #2 to `Encode'. Expected a number > 0, got %s", maxLineLength), 2)
|
||||
end
|
||||
end
|
||||
|
||||
if lineEnding == nil then
|
||||
lineEnding = "\r\n"
|
||||
elseif type(lineEnding) ~= "string" then
|
||||
error(format("Bad argument #3 to `Encode'. Expected string, got %q", type(lineEnding)), 2)
|
||||
end
|
||||
|
||||
local currentLength = 0
|
||||
for i = 1, #text, 3 do
|
||||
local a, b, c = strbyte(text, i, i+2)
|
||||
local nilNum = 0
|
||||
if not b then
|
||||
nilNum, b, c = 2, 0, 0
|
||||
elseif not c then
|
||||
nilNum, c = 1, 0
|
||||
end
|
||||
|
||||
local num = a * 2^16 + b * 2^8 + c
|
||||
local d = num % 2^6;num = (num - d) / 2^6
|
||||
c = num % 2^6;num = (num - c) / 2^6
|
||||
b = num % 2^6;num = (num - b) / 2^6
|
||||
a = num % 2^6
|
||||
|
||||
t[#t+1] = numToChar[a]
|
||||
t[#t+1] = numToChar[b]
|
||||
t[#t+1] = (nilNum >= 2) and "=" or numToChar[c]
|
||||
t[#t+1] = (nilNum >= 1) and "=" or numToChar[d]
|
||||
|
||||
currentLength = currentLength + 4
|
||||
if maxLineLength and (currentLength % maxLineLength) == 0 then
|
||||
t[#t+1] = lineEnding
|
||||
end
|
||||
end
|
||||
|
||||
local s = tconcat(t)
|
||||
wipe(t)
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
local t2 = {}
|
||||
|
||||
--- Decode a Base64-encoded string into a bytestring
|
||||
-- this will raise an error if the data passed in is not a Base64-encoded string
|
||||
-- this will ignore whitespace, but not invalid characters
|
||||
-- @param text a Base64-encoded string
|
||||
-- @usage LibBase64.Encode("SGVsbG8sIGhvdyBhcmUgeW91IGRvaW5nIHRvZGF5Pw==") == "Hello, how are you doing today?"
|
||||
-- @return a bytestring
|
||||
function LibBase64:Decode(text)
|
||||
if type(text) ~= "string" then
|
||||
error(format("Bad argument #1 to `Decode'. Expected string, got %q", type(text)), 2)
|
||||
end
|
||||
|
||||
for i = 1, #text do
|
||||
local byte = strbyte(text, i)
|
||||
if not (whitespace[byte] or byte == equals_byte) then
|
||||
local num = byteToNum[byte]
|
||||
if not num then
|
||||
wipe(t2)
|
||||
|
||||
error(format("Bad argument #1 to `Decode'. Received an invalid char: %q", strsub(text, i, i)), 2)
|
||||
end
|
||||
|
||||
t2[#t2+1] = num
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #t2, 4 do
|
||||
local a, b, c, d = t2[i], t2[i+1], t2[i+2], t2[i+3]
|
||||
local nilNum = 0
|
||||
if not c then
|
||||
nilNum, c, d = 2, 0, 0
|
||||
elseif not d then
|
||||
nilNum, d = 1, 0
|
||||
end
|
||||
|
||||
local num = a * 2^18 + b * 2^12 + c * 2^6 + d
|
||||
c = num % 2^8;num = (num - c) / 2^8
|
||||
b = num % 2^8;num = (num - b) / 2^8
|
||||
a = num % 2^8
|
||||
|
||||
t[#t+1] = strchar(a)
|
||||
if nilNum < 2 then t[#t+1] = strchar(b) end
|
||||
if nilNum < 1 then t[#t+1] = strchar(c) end
|
||||
end
|
||||
|
||||
wipe(t2)
|
||||
|
||||
local s = tconcat(t)
|
||||
wipe(t)
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
function LibBase64:IsBase64(text)
|
||||
if type(text) ~= "string" then
|
||||
error(format("Bad argument #1 to `IsBase64'. Expected string, got %q", type(text)), 2)
|
||||
end
|
||||
|
||||
if #text % 4 ~= 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
for i = 1, #text do
|
||||
local byte = strbyte(text, i)
|
||||
if not (whitespace[byte] or byte == equals_byte) then
|
||||
local num = byteToNum[byte]
|
||||
if not num then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
@@ -0,0 +1,191 @@
|
||||
|
||||
local MAJOR, MINOR = "LibChatAnims", 1 -- Bump minor on changes
|
||||
local LCA = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
if not LCA then return end -- No upgrade needed
|
||||
|
||||
LCA.animations = LCA.animations or {} -- Animation storage
|
||||
local anims = LCA.animations
|
||||
|
||||
----------------------------------------------------
|
||||
-- Note, most of this code is simply replicated from
|
||||
-- Blizzard's FloatingChatFrame.lua file.
|
||||
-- The only real changes are the creation and use
|
||||
-- of animations vs the use of UIFrameFlash.
|
||||
--
|
||||
|
||||
FCFDockOverflowButton_UpdatePulseState = function(self)
|
||||
local dock = self:GetParent()
|
||||
local shouldPulse = false
|
||||
for _, chatFrame in pairs(FCFDock_GetChatFrames(dock)) do
|
||||
local chatTab = _G[chatFrame:GetName().."Tab"]
|
||||
if ( not chatFrame.isStaticDocked and chatTab.alerting) then
|
||||
-- Make sure the rects are valid. (Not always the case when resizing the WoW client
|
||||
if ( not chatTab:GetRight() or not dock.scrollFrame:GetRight() ) then
|
||||
return false
|
||||
end
|
||||
-- Check if it's off the screen.
|
||||
local DELTA = 3 -- Chosen through experimentation
|
||||
if ( chatTab:GetRight() < (dock.scrollFrame:GetLeft() + DELTA) or chatTab:GetLeft() > (dock.scrollFrame:GetRight() - DELTA) ) then
|
||||
shouldPulse = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local tex = self:GetHighlightTexture()
|
||||
if shouldPulse then
|
||||
if not anims[tex] then
|
||||
anims[tex] = tex:CreateAnimationGroup()
|
||||
|
||||
local fade1 = anims[tex]:CreateAnimation("Alpha")
|
||||
fade1:SetDuration(1)
|
||||
fade1:SetChange(1)
|
||||
fade1:SetOrder(1)
|
||||
|
||||
local fade2 = anims[tex]:CreateAnimation("Alpha")
|
||||
fade2:SetDuration(1)
|
||||
fade2:SetChange(-1)
|
||||
fade2:SetOrder(2)
|
||||
end
|
||||
tex:Show()
|
||||
tex:SetAlpha(0)
|
||||
anims[tex]:SetLooping("REPEAT")
|
||||
anims[tex]:Play()
|
||||
|
||||
self:LockHighlight()
|
||||
self.alerting = true
|
||||
else
|
||||
if anims[tex] then
|
||||
anims[tex]:Stop()
|
||||
end
|
||||
self:UnlockHighlight()
|
||||
tex:SetAlpha(1)
|
||||
tex:Show()
|
||||
self.alerting = false
|
||||
end
|
||||
|
||||
if self.list:IsShown() then
|
||||
FCFDockOverflowList_Update(self.list, dock)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
FCFDockOverflowListButton_SetValue = function(button, chatFrame)
|
||||
local chatTab = _G[chatFrame:GetName().."Tab"]
|
||||
button.chatFrame = chatFrame
|
||||
button:SetText(chatFrame.name)
|
||||
|
||||
local colorTable = chatTab.selectedColorTable or DEFAULT_TAB_SELECTED_COLOR_TABLE
|
||||
|
||||
if chatTab.selectedColorTable then
|
||||
button:GetFontString():SetTextColor(colorTable.r, colorTable.g, colorTable.b)
|
||||
else
|
||||
button:GetFontString():SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
|
||||
end
|
||||
|
||||
button.glow:SetVertexColor(colorTable.r, colorTable.g, colorTable.b)
|
||||
|
||||
if chatTab.conversationIcon then
|
||||
button.conversationIcon:SetVertexColor(colorTable.r, colorTable.g, colorTable.b)
|
||||
button.conversationIcon:Show()
|
||||
else
|
||||
button.conversationIcon:Hide()
|
||||
end
|
||||
|
||||
if chatTab.alerting then
|
||||
button.alerting = true
|
||||
if not anims[button.glow] then
|
||||
anims[button.glow] = button.glow:CreateAnimationGroup()
|
||||
|
||||
local fade1 = anims[button.glow]:CreateAnimation("Alpha")
|
||||
fade1:SetDuration(1)
|
||||
fade1:SetChange(1)
|
||||
fade1:SetOrder(1)
|
||||
|
||||
local fade2 = anims[button.glow]:CreateAnimation("Alpha")
|
||||
fade2:SetDuration(1)
|
||||
fade2:SetChange(-1)
|
||||
fade2:SetOrder(2)
|
||||
end
|
||||
button.glow:Show()
|
||||
button.glow:SetAlpha(0)
|
||||
anims[button.glow]:SetLooping("REPEAT")
|
||||
anims[button.glow]:Play()
|
||||
else
|
||||
button.alerting = false
|
||||
if anims[button.glow] then
|
||||
anims[button.glow]:Stop()
|
||||
end
|
||||
button.glow:Hide()
|
||||
end
|
||||
button:Show()
|
||||
end
|
||||
|
||||
FCF_StartAlertFlash = function(chatFrame)
|
||||
local chatTab = _G[chatFrame:GetName().."Tab"]
|
||||
|
||||
if chatFrame.minFrame then
|
||||
if not anims[chatFrame.minFrame] then
|
||||
anims[chatFrame.minFrame] = chatFrame.minFrame.glow:CreateAnimationGroup()
|
||||
|
||||
local fade1 = anims[chatFrame.minFrame]:CreateAnimation("Alpha")
|
||||
fade1:SetDuration(1)
|
||||
fade1:SetChange(1)
|
||||
fade1:SetOrder(1)
|
||||
|
||||
local fade2 = anims[chatFrame.minFrame]:CreateAnimation("Alpha")
|
||||
fade2:SetDuration(1)
|
||||
fade2:SetChange(-1)
|
||||
fade2:SetOrder(2)
|
||||
end
|
||||
chatFrame.minFrame.glow:Show()
|
||||
chatFrame.minFrame.glow:SetAlpha(0)
|
||||
anims[chatFrame.minFrame]:SetLooping("REPEAT")
|
||||
anims[chatFrame.minFrame]:Play()
|
||||
chatFrame.minFrame.alerting = true
|
||||
end
|
||||
|
||||
if not anims[chatTab.glow] then
|
||||
anims[chatTab.glow] = chatTab.glow:CreateAnimationGroup()
|
||||
|
||||
local fade1 = anims[chatTab.glow]:CreateAnimation("Alpha")
|
||||
fade1:SetDuration(1)
|
||||
fade1:SetChange(1)
|
||||
fade1:SetOrder(1)
|
||||
|
||||
local fade2 = anims[chatTab.glow]:CreateAnimation("Alpha")
|
||||
fade2:SetDuration(1)
|
||||
fade2:SetChange(-1)
|
||||
fade2:SetOrder(2)
|
||||
end
|
||||
chatTab.glow:Show()
|
||||
chatTab.glow:SetAlpha(0)
|
||||
anims[chatTab.glow]:SetLooping("REPEAT")
|
||||
anims[chatTab.glow]:Play()
|
||||
chatTab.alerting = true
|
||||
|
||||
FCFTab_UpdateAlpha(chatFrame)
|
||||
FCFDockOverflowButton_UpdatePulseState(GENERAL_CHAT_DOCK.overflowButton)
|
||||
end
|
||||
|
||||
FCF_StopAlertFlash = function(chatFrame)
|
||||
local chatTab = _G[chatFrame:GetName().."Tab"]
|
||||
|
||||
if chatFrame.minFrame then
|
||||
if anims[chatFrame.minFrame] then
|
||||
anims[chatFrame.minFrame]:Stop()
|
||||
end
|
||||
chatFrame.minFrame.glow:Hide()
|
||||
chatFrame.minFrame.alerting = false
|
||||
end
|
||||
|
||||
if anims[chatTab.glow] then
|
||||
anims[chatTab.glow]:Stop()
|
||||
end
|
||||
chatTab.glow:Hide()
|
||||
chatTab.alerting = false
|
||||
|
||||
FCFTab_UpdateAlpha(chatFrame)
|
||||
FCFDockOverflowButton_UpdatePulseState(GENERAL_CHAT_DOCK.overflowButton)
|
||||
end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,90 @@
|
||||
|
||||
assert(LibStub, "LibDataBroker-1.1 requires LibStub")
|
||||
assert(LibStub:GetLibrary("CallbackHandler-1.0", true), "LibDataBroker-1.1 requires CallbackHandler-1.0")
|
||||
|
||||
local lib, oldminor = LibStub:NewLibrary("LibDataBroker-1.1", 4)
|
||||
if not lib then return end
|
||||
oldminor = oldminor or 0
|
||||
|
||||
|
||||
lib.callbacks = lib.callbacks or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
|
||||
lib.attributestorage, lib.namestorage, lib.proxystorage = lib.attributestorage or {}, lib.namestorage or {}, lib.proxystorage or {}
|
||||
local attributestorage, namestorage, callbacks = lib.attributestorage, lib.namestorage, lib.callbacks
|
||||
|
||||
if oldminor < 2 then
|
||||
lib.domt = {
|
||||
__metatable = "access denied",
|
||||
__index = function(self, key) return attributestorage[self] and attributestorage[self][key] end,
|
||||
}
|
||||
end
|
||||
|
||||
if oldminor < 3 then
|
||||
lib.domt.__newindex = function(self, key, value)
|
||||
if not attributestorage[self] then attributestorage[self] = {} end
|
||||
if attributestorage[self][key] == value then return end
|
||||
attributestorage[self][key] = value
|
||||
local name = namestorage[self]
|
||||
if not name then return end
|
||||
callbacks:Fire("LibDataBroker_AttributeChanged", name, key, value, self)
|
||||
callbacks:Fire("LibDataBroker_AttributeChanged_"..name, name, key, value, self)
|
||||
callbacks:Fire("LibDataBroker_AttributeChanged_"..name.."_"..key, name, key, value, self)
|
||||
callbacks:Fire("LibDataBroker_AttributeChanged__"..key, name, key, value, self)
|
||||
end
|
||||
end
|
||||
|
||||
if oldminor < 2 then
|
||||
function lib:NewDataObject(name, dataobj)
|
||||
if self.proxystorage[name] then return end
|
||||
|
||||
if dataobj then
|
||||
assert(type(dataobj) == "table", "Invalid dataobj, must be nil or a table")
|
||||
self.attributestorage[dataobj] = {}
|
||||
for i,v in pairs(dataobj) do
|
||||
self.attributestorage[dataobj][i] = v
|
||||
dataobj[i] = nil
|
||||
end
|
||||
end
|
||||
dataobj = setmetatable(dataobj or {}, self.domt)
|
||||
self.proxystorage[name], self.namestorage[dataobj] = dataobj, name
|
||||
self.callbacks:Fire("LibDataBroker_DataObjectCreated", name, dataobj)
|
||||
return dataobj
|
||||
end
|
||||
end
|
||||
|
||||
if oldminor < 1 then
|
||||
function lib:DataObjectIterator()
|
||||
return pairs(self.proxystorage)
|
||||
end
|
||||
|
||||
function lib:GetDataObjectByName(dataobjectname)
|
||||
return self.proxystorage[dataobjectname]
|
||||
end
|
||||
|
||||
function lib:GetNameByDataObject(dataobject)
|
||||
return self.namestorage[dataobject]
|
||||
end
|
||||
end
|
||||
|
||||
if oldminor < 4 then
|
||||
local next = pairs(attributestorage)
|
||||
function lib:pairs(dataobject_or_name)
|
||||
local t = type(dataobject_or_name)
|
||||
assert(t == "string" or t == "table", "Usage: ldb:pairs('dataobjectname') or ldb:pairs(dataobject)")
|
||||
|
||||
local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
|
||||
assert(attributestorage[dataobj], "Data object not found")
|
||||
|
||||
return next, attributestorage[dataobj], nil
|
||||
end
|
||||
|
||||
local ipairs_iter = ipairs(attributestorage)
|
||||
function lib:ipairs(dataobject_or_name)
|
||||
local t = type(dataobject_or_name)
|
||||
assert(t == "string" or t == "table", "Usage: ldb:ipairs('dataobjectname') or ldb:ipairs(dataobject)")
|
||||
|
||||
local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
|
||||
assert(attributestorage[dataobj], "Data object not found")
|
||||
|
||||
return ipairs_iter, attributestorage[dataobj], 0
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,328 @@
|
||||
--[[
|
||||
LibDualSpec-1.0 - Adds dual spec support to individual AceDB-3.0 databases
|
||||
Copyright (C) 2009 Adirelle
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Redistribution of a stand alone version is strictly prohibited without
|
||||
prior written authorization from the LibDualSpec project manager.
|
||||
* Neither the name of the LibDualSpec authors nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
--]]
|
||||
|
||||
local MAJOR, MINOR = "LibDualSpec-1.0", 4
|
||||
assert(LibStub, MAJOR.." requires LibStub")
|
||||
local lib = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
if not lib then return end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Library data
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
lib.talentGroup = lib.talentGroup or GetActiveTalentGroup()
|
||||
lib.eventFrame = lib.eventFrame or CreateFrame("Frame")
|
||||
|
||||
lib.registry = lib.registry or {}
|
||||
lib.options = lib.options or {}
|
||||
lib.mixin = lib.mixin or {}
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Locals
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local registry = lib.registry
|
||||
local options = lib.options
|
||||
local mixin = lib.mixin
|
||||
|
||||
-- "Externals"
|
||||
local AceDB3 = LibStub('AceDB-3.0', true)
|
||||
local AceDBOptions3 = LibStub('AceDBOptions-3.0', true)
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Localization
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local L_DUALSPEC_DESC, L_ENABLED, L_ENABLED_DESC, L_DUAL_PROFILE, L_DUAL_PROFILE_DESC
|
||||
|
||||
do
|
||||
L_DUALSPEC_DESC = "When enabled, this feature allow you to select a different "..
|
||||
"profile for each talent spec. The dual profile will be swapped with the "..
|
||||
"current profile each time you switch from a talent spec to the other."
|
||||
L_ENABLED = 'Enable dual profile'
|
||||
L_ENABLED_DESC = 'Check this box to automatically swap profiles on talent switch.'
|
||||
L_DUAL_PROFILE = 'Dual profile'
|
||||
L_DUAL_PROFILE_DESC = 'Select the profile to swap with on talent switch.'
|
||||
|
||||
local locale = GetLocale()
|
||||
if locale == "frFR" then
|
||||
L_DUALSPEC_DESC = "Lorsqu'elle est activée, cette fonctionnalité vous permet de choisir un profil différent pour chaque spécialisation de talents. Le second profil sera échangé avec le profil courant chaque fois que vous passerez d'une spécialisation à l'autre."
|
||||
L_DUAL_PROFILE = "Second profil"
|
||||
L_DUAL_PROFILE_DESC = "Sélectionnez le profil à échanger avec le profil courant lors du changement de spécialisation."
|
||||
L_ENABLED = "Activez le second profil"
|
||||
L_ENABLED_DESC = "Cochez cette case pour échanger automatiquement les profils lors d'un changement de spécialisation."
|
||||
elseif locale == "deDE" then
|
||||
L_DUALSPEC_DESC = "Wenn aktiv, wechselt dieses Feature bei jedem Wechsel der dualen Talentspezialisierung das Profil. Das duale Profil wird beim Wechsel automatisch mit dem derzeit aktiven Profil getauscht."
|
||||
L_DUAL_PROFILE = "Duales Profil"
|
||||
L_DUAL_PROFILE_DESC = "Wähle das Profil, das beim Wechsel der Talente aktiviert wird."
|
||||
L_ENABLED = "Aktiviere Duale Profile"
|
||||
L_ENABLED_DESC = "Aktiviere diese Option, um beim Talentwechsel automatisch zwischen den Profilen zu wechseln."
|
||||
elseif locale == "koKR" then
|
||||
L_DUALSPEC_DESC = "|n전문화 변경 시 현재 프로필을 첫 번째 전문화 때에, 여기서 설정하는 프로필을 두 번째 전문화 때에 적용시킵니다.|n전문화별로 설정을 다르게 하고 싶을 때 아주 유용합니다."
|
||||
L_DUAL_PROFILE = "두번째 전문화 때 프로필"
|
||||
L_DUAL_PROFILE_DESC = "두번째 전문화 때 적용할 프로필을 선택하세요."
|
||||
L_ENABLED = "이중 프로필 사용"
|
||||
L_ENABLED_DESC = "전문화에 따라 다른 프로필을 적용시킵니다."
|
||||
elseif locale == "ruRU" then
|
||||
L_DUALSPEC_DESC = "Двойной профиль позволяет вам выбрать различные профили для каждой раскладки талантов. Профили будут переключаться каждый раз, когда вы переключаете раскладку талантов."
|
||||
L_DUAL_PROFILE = "Второй профиль"
|
||||
L_DUAL_PROFILE_DESC = "Выберите профиль, который необходимо активировать при переключениии талантов."
|
||||
L_ENABLED = "Включить двойной профиль"
|
||||
L_ENABLED_DESC = "Включите эту опцию для автоматического переключения между профилями при переключении раскладки талантов."
|
||||
elseif locale == "zhCN" then
|
||||
L_DUALSPEC_DESC = "启时,你可以为你的双天赋设定另一组配置文件,你的双重配置文件将在你转换天赋时自动与目前使用配置文件交换。"
|
||||
L_DUAL_PROFILE = "双重配置文件"
|
||||
L_DUAL_PROFILE_DESC = "选择转换天赋时所要使用的配置文件"
|
||||
L_ENABLED = "开启双重配置文件"
|
||||
L_ENABLED_DESC = "勾选以便转换天赋时自动交换配置文件。"
|
||||
elseif locale == "zhTW" then
|
||||
L_DUALSPEC_DESC = "啟用時,你可以為你的雙天賦設定另一組設定檔。你的雙設定檔將在你轉換天賦時自動與目前使用設定檔交換。"
|
||||
L_DUAL_PROFILE = "雙設定檔"
|
||||
L_DUAL_PROFILE_DESC = "選擇轉換天賦後所要使用的設定檔"
|
||||
L_ENABLED = "啟用雙設定檔"
|
||||
L_ENABLED_DESC = "勾選以在轉換天賦時自動交換設定檔"
|
||||
elseif locale == "esES" then
|
||||
L_DUALSPEC_DESC = "Si está activa, esta característica te permite seleccionar un perfil distinto para cada configuración de talentos. El perfil secundario será intercambiado por el activo cada vez que cambies de una configuración de talentos a otra."
|
||||
L_DUAL_PROFILE = "Perfil secundario"
|
||||
L_DUAL_PROFILE_DESC = "Elige el perfil secundario que se usará cuando cambies de talentos."
|
||||
L_ENABLED = "Activar perfil secundario"
|
||||
L_ENABLED_DESC = "Activa esta casilla para alternar automáticamente entre prefiles cuando cambies de talentos."
|
||||
end
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Mixin
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
--- Get dual spec feature status.
|
||||
-- @return (boolean) true is dual spec feature enabled.
|
||||
-- @name enhancedDB:IsDualSpecEnabled
|
||||
function mixin:IsDualSpecEnabled()
|
||||
return registry[self].db.char.enabled
|
||||
end
|
||||
|
||||
--- Enable/disabled dual spec feature.
|
||||
-- @param enabled (boolean) true to enable dual spec feature, false to disable it.
|
||||
-- @name enhancedDB:SetDualSpecEnabled
|
||||
function mixin:SetDualSpecEnabled(enabled)
|
||||
local db = registry[self].db
|
||||
if enabled and not db.char.talentGroup then
|
||||
db.char.talentGroup = lib.talentGroup
|
||||
db.char.profile = self:GetCurrentProfile()
|
||||
db.char.enabled = true
|
||||
else
|
||||
db.char.enabled = enabled
|
||||
self:CheckDualSpecState()
|
||||
end
|
||||
end
|
||||
|
||||
--- Get the alternate profile name.
|
||||
-- Defaults to the current profile.
|
||||
-- @return (string) Alternate profile name.
|
||||
-- @name enhancedDB:GetDualSpecProfile
|
||||
function mixin:GetDualSpecProfile()
|
||||
return registry[self].db.char.profile or self:GetCurrentProfile()
|
||||
end
|
||||
|
||||
--- Set the alternate profile name.
|
||||
-- No validation are done to ensure the profile is valid.
|
||||
-- @param profileName (string) the profile name to use.
|
||||
-- @name enhancedDB:SetDualSpecProfile
|
||||
function mixin:SetDualSpecProfile(profileName)
|
||||
registry[self].db.char.profile = profileName
|
||||
end
|
||||
|
||||
--- Check if a profile swap should occur.
|
||||
-- Do nothing if the dual spec feature is disabled. In the other
|
||||
-- case, if the internally stored talent spec is different from the
|
||||
-- actual active talent spec, the database swaps to the alternate profile.
|
||||
-- There is normally no reason to call this method directly as LibDualSpec
|
||||
-- takes care of calling it at appropriate times.
|
||||
-- @name enhancedDB:CheckDualSpecState
|
||||
function mixin:CheckDualSpecState()
|
||||
local db = registry[self].db
|
||||
if db.char.enabled and db.char.talentGroup ~= lib.talentGroup then
|
||||
local currentProfile = self:GetCurrentProfile()
|
||||
local newProfile = db.char.profile
|
||||
db.char.talentGroup = lib.talentGroup
|
||||
if newProfile ~= currentProfile then
|
||||
db.char.profile = currentProfile
|
||||
self:SetProfile(newProfile)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- AceDB-3.0 support
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local function EmbedMixin(target)
|
||||
for k,v in pairs(mixin) do
|
||||
rawset(target, k, v)
|
||||
end
|
||||
end
|
||||
|
||||
-- Upgrade existing mixins
|
||||
for target in pairs(registry) do
|
||||
EmbedMixin(target)
|
||||
end
|
||||
|
||||
-- Actually enhance the database
|
||||
-- This is used on first initialization and everytime the database is reset using :ResetDB
|
||||
function lib:_EnhanceDatabase(event, target)
|
||||
registry[target].db = target:GetNamespace(MAJOR, true) or target:RegisterNamespace(MAJOR)
|
||||
EmbedMixin(target)
|
||||
target:CheckDualSpecState()
|
||||
end
|
||||
|
||||
--- Embed dual spec feature into an existing AceDB-3.0 database.
|
||||
-- LibDualSpec specific methods are added to the instance.
|
||||
-- @name LibDualSpec:EnhanceDatabase
|
||||
-- @param target (table) the AceDB-3.0 instance.
|
||||
-- @param name (string) a user-friendly name of the database (best bet is the addon name).
|
||||
function lib:EnhanceDatabase(target, name)
|
||||
AceDB3 = AceDB3 or LibStub('AceDB-3.0', true)
|
||||
if type(target) ~= "table" then
|
||||
error("Usage: LibDualSpec:EnhanceDatabase(target, name): target should be a table.", 2)
|
||||
elseif type(name) ~= "string" then
|
||||
error("Usage: LibDualSpec:EnhanceDatabase(target, name): name should be a string.", 2)
|
||||
elseif not AceDB3 or not AceDB3.db_registry[target] then
|
||||
error("Usage: LibDualSpec:EnhanceDatabase(target, name): target should be an AceDB-3.0 database.", 2)
|
||||
elseif target.parent then
|
||||
error("Usage: LibDualSpec:EnhanceDatabase(target, name): cannot enhance a namespace.", 2)
|
||||
elseif registry[target] then
|
||||
return
|
||||
end
|
||||
registry[target] = { name = name }
|
||||
lib:_EnhanceDatabase("EnhanceDatabase", target)
|
||||
target.RegisterCallback(lib, "OnDatabaseReset", "_EnhanceDatabase")
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- AceDBOptions-3.0 support
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local function NoDualSpec()
|
||||
return GetNumTalentGroups() == 1
|
||||
end
|
||||
|
||||
options.dualSpecDesc = {
|
||||
name = L_DUALSPEC_DESC,
|
||||
type = 'description',
|
||||
order = 40.1,
|
||||
hidden = NoDualSpec,
|
||||
}
|
||||
|
||||
options.enabled = {
|
||||
name = L_ENABLED,
|
||||
desc = L_ENABLED_DESC,
|
||||
type = 'toggle',
|
||||
order = 40.2,
|
||||
get = function(info) return info.handler.db:IsDualSpecEnabled() end,
|
||||
set = function(info, value) info.handler.db:SetDualSpecEnabled(value) end,
|
||||
hidden = NoDualSpec,
|
||||
}
|
||||
|
||||
options.dualProfile = {
|
||||
name = L_DUAL_PROFILE,
|
||||
desc = L_DUAL_PROFILE_DESC,
|
||||
type = 'select',
|
||||
order = 40.3,
|
||||
get = function(info) return info.handler.db:GetDualSpecProfile() end,
|
||||
set = function(info, value) info.handler.db:SetDualSpecProfile(value) end,
|
||||
values = "ListProfiles",
|
||||
arg = "common",
|
||||
hidden = NoDualSpec,
|
||||
disabled = function(info) return not info.handler.db:IsDualSpecEnabled() end,
|
||||
}
|
||||
|
||||
--- Embed dual spec options into an existing AceDBOptions-3.0 option table.
|
||||
-- @name LibDualSpec:EnhanceOptions
|
||||
-- @param optionTable (table) The option table returned by AceDBOptions-3.0.
|
||||
-- @param target (table) The AceDB-3.0 the options operate on.
|
||||
function lib:EnhanceOptions(optionTable, target)
|
||||
AceDBOptions3 = AceDBOptions3 or LibStub('AceDBOptions-3.0', true)
|
||||
if type(optionTable) ~= "table" then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): optionTable should be a table.", 2)
|
||||
elseif type(target) ~= "table" then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): target should be a table.", 2)
|
||||
elseif not (AceDBOptions3 and AceDBOptions3.optionTables[target]) then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): optionTable is not an AceDBOptions-3.0 table.", 2)
|
||||
elseif optionTable.handler.db ~= target then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): optionTable must be the option table of target.", 2)
|
||||
elseif not registry[target] then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): EnhanceDatabase should be called before EnhanceOptions(optionTable, target).", 2)
|
||||
elseif optionTable.plugins and optionTable.plugins[MAJOR] then
|
||||
return
|
||||
end
|
||||
if not optionTable.plugins then
|
||||
optionTable.plugins = {}
|
||||
end
|
||||
optionTable.plugins[MAJOR] = options
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Inspection
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local function iterator(registry, key)
|
||||
local data
|
||||
key, data = next(registry, key)
|
||||
if key then
|
||||
return key, data.name
|
||||
end
|
||||
end
|
||||
|
||||
--- Iterate through enhanced AceDB3.0 instances.
|
||||
-- The iterator returns (instance, name) pairs where instance and name are the
|
||||
-- arguments that were provided to lib:EnhanceDatabase.
|
||||
-- @name LibDualSpec:IterateDatabases
|
||||
-- @return Values to be used in a for .. in .. do statement.
|
||||
function lib:IterateDatabases()
|
||||
return iterator, lib.registry
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Switching logic
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
lib.eventFrame:RegisterEvent('PLAYER_TALENT_UPDATE')
|
||||
lib.eventFrame:SetScript('OnEvent', function()
|
||||
local newTalentGroup = GetActiveTalentGroup()
|
||||
if lib.talentGroup ~= newTalentGroup then
|
||||
lib.talentGroup = newTalentGroup
|
||||
for target in pairs(registry) do
|
||||
target:CheckDualSpecState()
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,335 @@
|
||||
local MAJOR, MINOR = "LibElvUIPlugin-1.0", 31
|
||||
local lib = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
if not lib then return end
|
||||
-- GLOBALS: ElvUI
|
||||
|
||||
--[[----------------------------
|
||||
Plugin Table Format: (for reference only).
|
||||
{
|
||||
name - name of the plugin
|
||||
callback - callback to call when ElvUI_OptionsUI is loaded
|
||||
isLib - plugin is a library
|
||||
version - version of the plugin (pulls version info from metadata, libraries can define their own)
|
||||
|
||||
-- After new version recieved from another user:
|
||||
old - plugin is old version
|
||||
newversion - newer version number
|
||||
}
|
||||
|
||||
LibElvUIPlugin API:
|
||||
RegisterPlugin(name, callback, isLib, libVersion)
|
||||
-- Registers a module with the given name and option callback:
|
||||
name - name of plugin
|
||||
verion - version number
|
||||
isLib - plugin is a library
|
||||
libVersion - plugin library version (optional, defaults to 1)
|
||||
|
||||
HookInitialize(table, function)
|
||||
-- Posthook ElvUI Initialize function:
|
||||
table - addon table
|
||||
function - function to call after Initialize (may be a string, that exists on the addons table: table['string'])
|
||||
----------------------------]]--
|
||||
|
||||
local pairs, ipairs = pairs, ipairs
|
||||
local tonumber, type = tonumber, type
|
||||
local ceil = math.ceil
|
||||
local format, gmatch, gsub, len, match, sub = string.format, string.gmatch, string.gsub, string.len, string.match, string.sub
|
||||
local tinsert, wipe = table.insert, table.wipe
|
||||
|
||||
local GetAddOnMetadata = GetAddOnMetadata
|
||||
local GetNumPartyMembers = GetNumRaidMembers
|
||||
local GetNumRaidMembers = GetNumRaidMembers
|
||||
local IsAddOnLoaded = IsAddOnLoaded
|
||||
local IsInInstance = IsInInstance
|
||||
local SendAddonMessage = SendAddonMessage
|
||||
|
||||
local UNKNOWN = UNKNOWN
|
||||
|
||||
lib.prefix = "ElvUIPluginVC"
|
||||
lib.plugins = {}
|
||||
lib.groupSize = 0
|
||||
lib.index = 0
|
||||
|
||||
local MSG_OUTDATED = "Your version of %s %s is out of date (latest is version %s). You can download the latest version from https://github.com/BanditTech/ElvUI-Ascension/"
|
||||
local HDR_CONFIG = "Plugins"
|
||||
local HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - Plugins Loaded (Green means you have current version, Red means out of date)"
|
||||
local INFO_BY = "by"
|
||||
local INFO_VERSION = "Version:"
|
||||
local INFO_NEW = "Newest:"
|
||||
local LIBRARY = "Library"
|
||||
|
||||
local locale = GetLocale()
|
||||
if locale == "deDE" then
|
||||
MSG_OUTDATED = "Deine Version von %s %s ist veraltet (akutelle Version ist %s). Du kannst die aktuelle Version von https://github.com/BanditTech/ElvUI-Ascension/ herunterrladen."
|
||||
HDR_CONFIG = "Plugins"
|
||||
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - Plugins geladen (Grün bedeutet du hast die aktuelle Version, Rot bedeutet es ist veraltet)"
|
||||
INFO_BY = "von"
|
||||
INFO_VERSION = "Version:"
|
||||
INFO_NEW = "Neuste:"
|
||||
LIBRARY = "Bibliothek"
|
||||
elseif locale == "ruRU" then
|
||||
MSG_OUTDATED = "Ваша версия %s %s устарела (последняя версия %s). Вы можете скачать последнюю версию на https://github.com/BanditTech/ElvUI-Ascension/"
|
||||
HDR_CONFIG = "Плагины"
|
||||
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - загруженные плагины (зеленый означает, что у вас последняя версия, красный - устаревшая)"
|
||||
INFO_BY = "от"
|
||||
INFO_VERSION = "Версия:"
|
||||
INFO_NEW = "Последняя:"
|
||||
LIBRARY = "Библиотека"
|
||||
elseif locale == "zhCN" then
|
||||
MSG_OUTDATED = "你的 %s %s 版本已经过期 (最新版本是 %s)。你可以从 https://github.com/BanditTech/ElvUI-Ascension/ 下载最新版本"
|
||||
HDR_CONFIG = "插件"
|
||||
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - 载入的插件 (绿色表示拥有当前版本, 红色表示版本已经过期)"
|
||||
INFO_BY = "作者"
|
||||
INFO_VERSION = "版本:"
|
||||
INFO_NEW = "最新:"
|
||||
LIBRARY = "库"
|
||||
elseif locale == "zhTW" then
|
||||
MSG_OUTDATED = "你的 %s %s 版本已經過期 (最新版本為 %s)。你可以透過 https://github.com/BanditTech/ElvUI-Ascension/ 下載最新的版本"
|
||||
HDR_CONFIG = "插件"
|
||||
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - 載入的插件 (綠色表示擁有當前版本, 紅色表示版本已經過期)"
|
||||
INFO_BY = "作者"
|
||||
INFO_VERSION = "版本:"
|
||||
INFO_NEW = "最新:"
|
||||
LIBRARY = "庫"
|
||||
end
|
||||
|
||||
local E
|
||||
local function checkElvUI()
|
||||
if not E then
|
||||
E = ElvUI[1]
|
||||
assert(E, "ElvUI not found.")
|
||||
end
|
||||
end
|
||||
|
||||
function lib:RegisterPlugin(name, callback, isLib, libVersion)
|
||||
checkElvUI()
|
||||
|
||||
local plugin = {
|
||||
name = name,
|
||||
callback = callback
|
||||
}
|
||||
|
||||
if isLib then
|
||||
plugin.isLib = true
|
||||
plugin.version = libVersion or 1
|
||||
else
|
||||
plugin.version = (name == MAJOR and MINOR) or GetAddOnMetadata(name, "Version") or UNKNOWN
|
||||
end
|
||||
|
||||
lib.plugins[name] = plugin
|
||||
|
||||
if not lib.registeredPrefix and E.global.general.versionCheck then
|
||||
lib.VCFrame:RegisterEvent("CHAT_MSG_ADDON")
|
||||
lib.VCFrame:RegisterEvent("RAID_ROSTER_UPDATE")
|
||||
lib.VCFrame:RegisterEvent("PARTY_MEMBERS_CHANGED")
|
||||
lib.VCFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
lib.registeredPrefix = true
|
||||
end
|
||||
|
||||
local loaded = IsAddOnLoaded("ElvUI_OptionsUI")
|
||||
if not loaded then
|
||||
lib.CFFrame:RegisterEvent("ADDON_LOADED")
|
||||
elseif loaded then
|
||||
if name ~= MAJOR then
|
||||
E.Options.args.plugins.args.plugins.name = lib:GeneratePluginList()
|
||||
end
|
||||
|
||||
if callback then
|
||||
callback()
|
||||
end
|
||||
end
|
||||
|
||||
return plugin
|
||||
end
|
||||
|
||||
local function SendVersionCheckMessage()
|
||||
lib:SendPluginVersionCheck(lib:GenerateVersionCheckMessage())
|
||||
end
|
||||
|
||||
function lib:DelayedSendVersionCheck(delay)
|
||||
if not E.SendPluginVersionCheck then
|
||||
E.SendPluginVersionCheck = SendVersionCheckMessage
|
||||
end
|
||||
|
||||
if not lib.SendMessageWaiting then
|
||||
lib.SendMessageWaiting = E:Delay(delay or 10, E.SendPluginVersionCheck)
|
||||
end
|
||||
end
|
||||
|
||||
function lib:OptionsUILoaded(_, addon)
|
||||
if addon == "ElvUI_OptionsUI" then
|
||||
lib:GetPluginOptions()
|
||||
|
||||
for _, plugin in pairs(lib.plugins) do
|
||||
if plugin.callback then
|
||||
plugin.callback()
|
||||
end
|
||||
end
|
||||
|
||||
lib.CFFrame:UnregisterEvent("ADDON_LOADED")
|
||||
end
|
||||
end
|
||||
|
||||
function lib:GenerateVersionCheckMessage()
|
||||
local list = ""
|
||||
for _, plugin in pairs(lib.plugins) do
|
||||
if plugin.name ~= MAJOR then
|
||||
list = list .. plugin.name .. "=" .. plugin.version .. ";"
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function lib:GetPluginOptions()
|
||||
E.Options.args.plugins = {
|
||||
order = -10,
|
||||
type = "group",
|
||||
name = HDR_CONFIG,
|
||||
guiInline = false,
|
||||
args = {
|
||||
pluginheader = {
|
||||
order = 1,
|
||||
type = "header",
|
||||
name = format(HDR_INFORMATION, MINOR)
|
||||
},
|
||||
plugins = {
|
||||
order = 2,
|
||||
type = "description",
|
||||
name = lib:GeneratePluginList()
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
do -- this will handle `8.1.5.0015` into `8.150015` etc
|
||||
local verStrip = function(a, b) return a..gsub(b, "%.", "") end
|
||||
function lib:StripVersion(version)
|
||||
local ver = gsub(version, "(%d-%.)([%d%.]+)", verStrip)
|
||||
return tonumber(ver)
|
||||
end
|
||||
end
|
||||
|
||||
function lib:VersionCheck(event, prefix, message, _, sender)
|
||||
if (event == "CHAT_MSG_ADDON" and prefix == lib.prefix) and (sender and message and not match(message, "^%s-$")) then
|
||||
if sender == E.myname then return end
|
||||
|
||||
if not E.pluginRecievedOutOfDateMessage then
|
||||
for name, version in gmatch(message, "([^=]+)=([%d%p]+);") do
|
||||
local plugin = (version and name) and lib.plugins[name]
|
||||
if plugin and plugin.version then
|
||||
local Pver, ver = lib:StripVersion(plugin.version), lib:StripVersion(version)
|
||||
if (ver and Pver) and (ver > Pver) then
|
||||
plugin.old, plugin.newversion = true, version
|
||||
local title = GetAddOnMetadata(plugin.name, "Title") or plugin.name
|
||||
E:Print(format(MSG_OUTDATED, title, plugin.version, plugin.newversion))
|
||||
E.pluginRecievedOutOfDateMessage = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif event == "PLAYER_ENTERING_WORLD" then
|
||||
lib:DelayedSendVersionCheck()
|
||||
else
|
||||
local numRaid = GetNumRaidMembers()
|
||||
local num = numRaid > 0 and numRaid or (GetNumPartyMembers() + 1)
|
||||
|
||||
if num ~= lib.groupSize then
|
||||
if num > 1 and num > lib.groupSize then
|
||||
lib:DelayedSendVersionCheck()
|
||||
end
|
||||
lib.groupSize = num
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function lib:GeneratePluginList()
|
||||
local list = ""
|
||||
for _, plugin in pairs(lib.plugins) do
|
||||
if plugin.name ~= MAJOR then
|
||||
local author = GetAddOnMetadata(plugin.name, "Author")
|
||||
local title = GetAddOnMetadata(plugin.name, "Title") or plugin.name
|
||||
local color = (plugin.old and E:RGBToHex(1, 0, 0)) or E:RGBToHex(0, 1, 0)
|
||||
list = list .. title
|
||||
if author then list = list .. " " .. INFO_BY .. " " .. author end
|
||||
list = list .. color .. (plugin.isLib and " " .. LIBRARY or " - " .. INFO_VERSION .. " " .. plugin.version)
|
||||
if plugin.old then list = list .. " (" .. INFO_NEW .. plugin.newversion .. ")" end
|
||||
list = list .. "|r\n"
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function lib:ClearSendMessageWait()
|
||||
lib.SendMessageWaiting = nil
|
||||
end
|
||||
|
||||
function lib:SendPluginVersionCheck(message)
|
||||
if (not message) or match(message, "^%s-$") then
|
||||
lib.ClearSendMessageWait()
|
||||
return
|
||||
end
|
||||
|
||||
local ChatType
|
||||
if GetNumRaidMembers() > 1 then
|
||||
local _, instanceType = IsInInstance()
|
||||
ChatType = instanceType == "pvp" and "BATTLEGROUND" or "RAID"
|
||||
elseif GetNumPartyMembers() > 0 then
|
||||
ChatType = "PARTY"
|
||||
end
|
||||
|
||||
if not ChatType then
|
||||
lib.ClearSendMessageWait()
|
||||
return
|
||||
end
|
||||
|
||||
local maxChar, msgLength = 254 - len(lib.prefix), len(message)
|
||||
if msgLength > maxChar then
|
||||
local delay, splitMessage = 0
|
||||
|
||||
for _ = 1, ceil(msgLength / maxChar) do
|
||||
splitMessage = match(sub(message, 1, maxChar), ".+;")
|
||||
if splitMessage then -- incase the string is over `maxChar` but doesnt contain `;`
|
||||
message = gsub(message, "^"..gsub(splitMessage, "([%-%.%+%[%]%(%)%$%^%%%?%*])", "%%%1"), "")
|
||||
E:Delay(delay, SendAddonMessage, lib.prefix, splitMessage, ChatType)
|
||||
delay = delay + 1
|
||||
end
|
||||
end
|
||||
|
||||
E:Delay(delay, lib.ClearSendMessageWait)
|
||||
else
|
||||
SendAddonMessage(lib.prefix, message, ChatType)
|
||||
lib.ClearSendMessageWait()
|
||||
end
|
||||
end
|
||||
|
||||
function lib.Initialized()
|
||||
if not lib.inits then return end
|
||||
|
||||
for _, initTbl in ipairs(lib.inits) do
|
||||
initTbl[2](initTbl[1])
|
||||
end
|
||||
|
||||
wipe(lib.inits)
|
||||
end
|
||||
|
||||
function lib:HookInitialize(tbl, func)
|
||||
if not (tbl and func) then return end
|
||||
|
||||
if type(func) == "string" then
|
||||
func = tbl[func]
|
||||
end
|
||||
|
||||
if not self.inits then
|
||||
self.inits = {}
|
||||
checkElvUI()
|
||||
hooksecurefunc(E, "Initialize", self.Initialized)
|
||||
end
|
||||
|
||||
tinsert(lib.inits, {tbl, func})
|
||||
end
|
||||
|
||||
lib.VCFrame = CreateFrame("Frame")
|
||||
lib.VCFrame:SetScript("OnEvent", lib.VersionCheck)
|
||||
|
||||
lib.CFFrame = CreateFrame("Frame")
|
||||
lib.CFFrame:SetScript("OnEvent", lib.OptionsUILoaded)
|
||||
@@ -0,0 +1,203 @@
|
||||
--[[
|
||||
Copyright 2013 João Cardoso
|
||||
CustomSearch is distributed under the terms of the GNU General Public License (Version 3).
|
||||
As a special exception, the copyright holders of this library give you permission to embed it
|
||||
with independent modules to produce an addon, regardless of the license terms of these
|
||||
independent modules, and to copy and distribute the resulting software under terms of your
|
||||
choice, provided that you also meet, for each embedded independent module, the terms and
|
||||
conditions of the license of that module. Permission is not granted to modify this library.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the library. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
This file is part of CustomSearch.
|
||||
--]]
|
||||
|
||||
local Lib = LibStub:NewLibrary('CustomSearch-1.0', 9)
|
||||
if not Lib then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--[[ Parsing ]]--
|
||||
|
||||
function Lib:Matches(object, search, filters)
|
||||
if object then
|
||||
self.filters = filters
|
||||
self.object = object
|
||||
|
||||
return self:MatchAll(search or '')
|
||||
end
|
||||
end
|
||||
|
||||
function Lib:MatchAll(search)
|
||||
for phrase in self:Clean(search):gmatch('[^&]+') do
|
||||
if not self:MatchAny(phrase) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function Lib:MatchAny(search)
|
||||
for phrase in search:gmatch('[^|]+') do
|
||||
if self:Match(phrase) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Lib:Match(search)
|
||||
local tag, rest = search:match('^%s*(%S+):(.*)$')
|
||||
if tag then
|
||||
tag = '^' .. tag
|
||||
search = rest
|
||||
end
|
||||
|
||||
local words = search:gmatch('%S+')
|
||||
local failed
|
||||
|
||||
for word in words do
|
||||
if word == self.OR then
|
||||
if failed then
|
||||
failed = false
|
||||
else
|
||||
break
|
||||
end
|
||||
|
||||
else
|
||||
local negate, rest = word:match('^([!~]=*)(.*)$')
|
||||
if negate or word == self.NOT_MATCH then
|
||||
word = rest and rest ~= '' and rest or words() or ''
|
||||
negate = -1
|
||||
else
|
||||
negate = 1
|
||||
end
|
||||
|
||||
local operator, rest = word:match('^(=*[<>]=*)(.*)$')
|
||||
if operator then
|
||||
word = rest ~= '' and rest or words()
|
||||
end
|
||||
|
||||
local result = self:Filter(tag, operator, word) and 1 or -1
|
||||
if result * negate ~= 1 then
|
||||
failed = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return not failed
|
||||
end
|
||||
|
||||
|
||||
--[[ Filtering ]]--
|
||||
|
||||
function Lib:Filter(tag, operator, search)
|
||||
if not search then
|
||||
return true
|
||||
end
|
||||
|
||||
if tag then
|
||||
for _, filter in pairs(self.filters) do
|
||||
for _, value in pairs(filter.tags or {}) do
|
||||
if value:find(tag) then
|
||||
return self:UseFilter(filter, operator, search)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
for _, filter in pairs(self.filters) do
|
||||
if not filter.onlyTags and self:UseFilter(filter, operator, search) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Lib:UseFilter(filter, operator, search)
|
||||
local data = {filter:canSearch(operator, search, self.object)}
|
||||
if data[1] then
|
||||
return filter:match(self.object, operator, unpack(data))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[ Utilities ]]--
|
||||
|
||||
function Lib:Find(search, ...)
|
||||
for i = 1, select('#', ...) do
|
||||
local text = select(i, ...)
|
||||
if text and self:Clean(text):find(search) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Lib:Clean(string)
|
||||
string = string:lower()
|
||||
string = string:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', function(c) return '%'..c end)
|
||||
|
||||
for accent, char in pairs(self.ACCENTS) do
|
||||
string = string:gsub(accent, char)
|
||||
end
|
||||
|
||||
return string
|
||||
end
|
||||
|
||||
function Lib:Compare(op, a, b)
|
||||
if op then
|
||||
if op:find('<') then
|
||||
if op:find('=') then
|
||||
return a <= b
|
||||
end
|
||||
|
||||
return a < b
|
||||
end
|
||||
|
||||
if op:find('>')then
|
||||
if op:find('=') then
|
||||
return a >= b
|
||||
end
|
||||
|
||||
return a > b
|
||||
end
|
||||
end
|
||||
|
||||
return a == b
|
||||
end
|
||||
|
||||
|
||||
--[[ Localization ]]--
|
||||
|
||||
do
|
||||
local no = {enUS = 'Not', frFR = 'Pas', deDE = 'Nicht', ruRU = 'Нет'}
|
||||
local just_or = {enUS = 'Or', frFR = 'Ou', deDE = 'Oder', ruRU = 'Или'}
|
||||
local accents = {
|
||||
a = {'à','â','ã','å'},
|
||||
e = {'è','é','ê','ê','ë'},
|
||||
i = {'ì', 'í', 'î', 'ï'},
|
||||
o = {'ó','ò','ô','õ'},
|
||||
u = {'ù', 'ú', 'û', 'ü'},
|
||||
c = {'ç'}, n = {'ñ'}
|
||||
}
|
||||
|
||||
Lib.ACCENTS = {}
|
||||
for char, accents in pairs(accents) do
|
||||
for _, accent in ipairs(accents) do
|
||||
Lib.ACCENTS[accent] = char
|
||||
end
|
||||
end
|
||||
|
||||
Lib.OR = Lib:Clean(just_or[GetLocale()] or "")
|
||||
Lib.NOT = no[GetLocale()] or NO
|
||||
Lib.NOT_MATCH = Lib:Clean(Lib.NOT)
|
||||
setmetatable(Lib, {__call = Lib.Matches})
|
||||
end
|
||||
|
||||
return Lib
|
||||
@@ -0,0 +1,287 @@
|
||||
--[[
|
||||
ItemSearch
|
||||
An item text search engine of some sort
|
||||
--]]
|
||||
|
||||
local Search = LibStub("CustomSearch-1.0")
|
||||
local Unfit = LibStub("Unfit-1.0")
|
||||
local Lib = LibStub:NewLibrary("LibItemSearch-1.2-ElvUI", 17)
|
||||
if Lib then
|
||||
Lib.Scanner = LibItemSearchTooltipScanner or CreateFrame("GameTooltip", "LibItemSearchTooltipScanner", UIParent, "GameTooltipTemplate")
|
||||
Lib.Filters = {}
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
--[[ User API ]]--
|
||||
|
||||
function Lib:Matches(link, search)
|
||||
return Search(link, search, self.Filters)
|
||||
end
|
||||
|
||||
function Lib:Tooltip(link, search)
|
||||
return link and self.Filters.tip:match(link, nil, search)
|
||||
end
|
||||
|
||||
function Lib:TooltipPhrase(link, search)
|
||||
return link and self.Filters.tipPhrases:match(link, nil, search)
|
||||
end
|
||||
|
||||
function Lib:InSet(link, search)
|
||||
if IsEquippableItem(link) then
|
||||
local id = tonumber(link:match("item:(%-?%d+)"))
|
||||
return self:BelongsToSet(id, (search or ""):lower())
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Internal API ]]--
|
||||
|
||||
if IsAddOnLoaded("ItemRack") then
|
||||
local sameID = ItemRack.SameID
|
||||
|
||||
function Lib:BelongsToSet(id, search)
|
||||
for name, set in pairs(ItemRackUser.Sets) do
|
||||
if name:sub(1,1) ~= "" and Search:Find(search, name) then
|
||||
for _, item in pairs(set.equip) do
|
||||
if sameID(id, item) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elseif IsAddOnLoaded("Wardrobe") then
|
||||
function Lib:BelongsToSet(id, search)
|
||||
for _, outfit in ipairs(Wardrobe.CurrentConfig.Outfit) do
|
||||
local name = outfit.OutfitName
|
||||
if Search:Find(search, name) then
|
||||
for _, item in pairs(outfit.Item) do
|
||||
if item.IsSlotUsed == 1 and item.ItemID == id then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
function Lib:BelongsToSet(id, search)
|
||||
for i = 1, GetNumEquipmentSets() do
|
||||
local name = GetEquipmentSetInfo(i)
|
||||
if Search:Find(search, name) then
|
||||
local items = GetEquipmentSetItemIDs(name)
|
||||
for _, item in pairs(items) do
|
||||
if id == item then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ General ]]--
|
||||
|
||||
Lib.Filters.name = {
|
||||
tags = {"n", "name"},
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and search
|
||||
end,
|
||||
|
||||
match = function(self, item, _, search)
|
||||
local name = item:match("%[(.-)%]")
|
||||
return Search:Find(search, name)
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.type = {
|
||||
tags = {"t", "type", "s", "slot"},
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and search
|
||||
end,
|
||||
|
||||
match = function(self, item, _, search)
|
||||
local type, subType, _, equipSlot = select(6, GetItemInfo(item))
|
||||
return Search:Find(search, type, subType, _G[equipSlot])
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.level = {
|
||||
tags = {"l", "level", "lvl", "ilvl"},
|
||||
|
||||
canSearch = function(self, _, search)
|
||||
return tonumber(search)
|
||||
end,
|
||||
|
||||
match = function(self, link, operator, num)
|
||||
local lvl = select(4, GetItemInfo(link))
|
||||
if lvl then
|
||||
return Search:Compare(operator, lvl, num)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.requiredlevel = {
|
||||
tags = {"r", "req", "rl", "reql", "reqlvl"},
|
||||
|
||||
canSearch = function(self, _, search)
|
||||
return tonumber(search)
|
||||
end,
|
||||
|
||||
match = function(self, link, operator, num)
|
||||
local lvl = select(5, GetItemInfo(link))
|
||||
if lvl then
|
||||
return Search:Compare(operator, lvl, num)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.sets = {
|
||||
tags = {"s", "set"},
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and search
|
||||
end,
|
||||
|
||||
match = function(self, link, _, search)
|
||||
return Lib:InSet(link, search)
|
||||
end,
|
||||
}
|
||||
|
||||
Lib.Filters.quality = {
|
||||
tags = {"q", "quality"},
|
||||
keywords = {},
|
||||
|
||||
canSearch = function(self, _, search)
|
||||
for quality, name in pairs(self.keywords) do
|
||||
if name:find(search) then
|
||||
return quality
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
match = function(self, link, operator, num)
|
||||
local quality = select(3, GetItemInfo(link))
|
||||
return Search:Compare(operator, quality, num)
|
||||
end,
|
||||
}
|
||||
|
||||
--[[
|
||||
0 Poor 9d9d9d
|
||||
1 Common ffffff
|
||||
2 Uncommon 1eff00
|
||||
3 Rare 0070dd
|
||||
4 Epic a335ee
|
||||
5 Legendary ff8000
|
||||
6 Artifact e6cc80
|
||||
7 Heirloom 00ccff
|
||||
]]
|
||||
for i = 0, 7 do -- Ascension change: was `#ITEM_QUALITY_COLORS` now `7`
|
||||
Lib.Filters.quality.keywords[i] = _G["ITEM_QUALITY" .. i .. "_DESC"]:lower()
|
||||
end
|
||||
|
||||
--[[ Classic Keywords ]]--
|
||||
|
||||
Lib.Filters.items = {
|
||||
keyword = ITEMS:lower(),
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and self.keyword:find(search)
|
||||
end,
|
||||
|
||||
match = function(self, link)
|
||||
return true
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.usable = {
|
||||
keyword = USABLE_ITEMS:lower(),
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and self.keyword:find(search)
|
||||
end,
|
||||
|
||||
match = function(self, link)
|
||||
if not Unfit:IsItemUnusable(link) then
|
||||
local lvl = select(5, GetItemInfo(link))
|
||||
return lvl and (lvl ~= 0 and lvl <= UnitLevel("player"))
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
--[[ Tooltips ]]--
|
||||
|
||||
Lib.Filters.tip = {
|
||||
tags = {"tt", "tip", "tooltip"},
|
||||
onlyTags = true,
|
||||
|
||||
canSearch = function(self, _, search)
|
||||
return search
|
||||
end,
|
||||
|
||||
match = function(self, link, _, search)
|
||||
if link:find("item:") then
|
||||
Lib.Scanner:SetOwner(UIParent, "ANCHOR_NONE")
|
||||
Lib.Scanner:SetHyperlink(link)
|
||||
|
||||
for i = 1, Lib.Scanner:NumLines() do
|
||||
if Search:Find(search, _G[Lib.Scanner:GetName() .. "TextLeft" .. i]:GetText()) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.tipPhrases = {
|
||||
canSearch = function(self, _, search)
|
||||
if #search >= 3 then
|
||||
for key, query in pairs(self.keywords) do
|
||||
if key:find(search) then
|
||||
return query
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
match = function(self, link, _, search)
|
||||
local id = link:match("item:(%d+)")
|
||||
if not id then
|
||||
return
|
||||
end
|
||||
|
||||
local cached = self.cache[search][id]
|
||||
if cached ~= nil then
|
||||
return cached
|
||||
end
|
||||
|
||||
Lib.Scanner:SetOwner(UIParent, "ANCHOR_NONE")
|
||||
Lib.Scanner:SetHyperlink(link)
|
||||
|
||||
local matches = false
|
||||
for i = 1, Lib.Scanner:NumLines() do
|
||||
if search == _G[Lib.Scanner:GetName() .. "TextLeft" .. i]:GetText() then
|
||||
matches = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
self.cache[search][id] = matches
|
||||
return matches
|
||||
end,
|
||||
|
||||
cache = setmetatable({}, {__index = function(t, k) local v = {} t[k] = v return v end}),
|
||||
keywords = {
|
||||
[ITEM_SOULBOUND:lower()] = ITEM_BIND_ON_PICKUP,
|
||||
[QUESTS_LABEL:lower()] = ITEM_BIND_QUEST,
|
||||
|
||||
["bound"] = ITEM_BIND_ON_PICKUP,
|
||||
["bop"] = ITEM_BIND_ON_PICKUP,
|
||||
["boe"] = ITEM_BIND_ON_EQUIP,
|
||||
["bou"] = ITEM_BIND_ON_USE,
|
||||
["boa"] = ITEM_BIND_TO_ACCOUNT,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="CustomSearch-1.0\CustomSearch-1.0.lua"/>
|
||||
<Script file="Unfit-1.0\Unfit-1.0.lua"/>
|
||||
<Script file="LibItemSearch-1.2.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,40 @@
|
||||
--[[
|
||||
Copyright 2011-2016 João Cardoso
|
||||
Unfit is distributed under the terms of the GNU General Public License (Version 3).
|
||||
As a special exception, the copyright holders of this library give you permission to embed it
|
||||
with independent modules to produce an addon, regardless of the license terms of these
|
||||
independent modules, and to copy and distribute the resulting software under terms of your
|
||||
choice, provided that you also meet, for each embedded independent module, the terms and
|
||||
conditions of the license of that module. Permission is not granted to modify this library.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the library. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
This file is part of Unfit.
|
||||
--]]
|
||||
|
||||
local Lib = LibStub:NewLibrary('Unfit-1.0', 9)
|
||||
if not Lib then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--[[ Data ]]--
|
||||
|
||||
Lib.unusable = {}
|
||||
Lib.cannotDual = nil
|
||||
|
||||
--[[ API ]]--
|
||||
|
||||
function Lib:IsItemUnusable(...)
|
||||
return false
|
||||
end
|
||||
|
||||
function Lib:IsClassUnusable(subclass, slot)
|
||||
return false
|
||||
end
|
||||
@@ -0,0 +1,245 @@
|
||||
--[[
|
||||
Name: LibSharedMedia-3.0
|
||||
Revision: $Revision: 62 $
|
||||
Author: Elkano (elkano@gmx.de)
|
||||
Inspired By: SurfaceLib by Haste/Otravi (troeks@gmail.com)
|
||||
Website: http://www.wowace.com/projects/libsharedmedia-3-0/
|
||||
Description: Shared handling of media data (fonts, sounds, textures, ...) between addons.
|
||||
Dependencies: LibStub, CallbackHandler-1.0
|
||||
License: LGPL v2.1
|
||||
]]
|
||||
|
||||
local MAJOR, MINOR = "LibSharedMedia-3.0", 3030001 -- 3.3.5 / increase manually on changes
|
||||
local lib = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not lib then return end
|
||||
|
||||
local _G = getfenv(0)
|
||||
|
||||
local pairs = _G.pairs
|
||||
local type = _G.type
|
||||
|
||||
local band = _G.bit.band
|
||||
local table_sort = _G.table.sort
|
||||
|
||||
local locale = GetLocale()
|
||||
local locale_is_western
|
||||
local LOCALE_MASK = 0
|
||||
lib.LOCALE_BIT_koKR = 1
|
||||
lib.LOCALE_BIT_ruRU = 2
|
||||
lib.LOCALE_BIT_zhCN = 4
|
||||
lib.LOCALE_BIT_zhTW = 8
|
||||
lib.LOCALE_BIT_western = 128
|
||||
|
||||
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
|
||||
|
||||
lib.callbacks = lib.callbacks or CallbackHandler:New(lib)
|
||||
|
||||
lib.DefaultMedia = lib.DefaultMedia or {}
|
||||
lib.MediaList = lib.MediaList or {}
|
||||
lib.MediaTable = lib.MediaTable or {}
|
||||
lib.MediaType = lib.MediaType or {}
|
||||
lib.OverrideMedia = lib.OverrideMedia or {}
|
||||
|
||||
local defaultMedia = lib.DefaultMedia
|
||||
local mediaList = lib.MediaList
|
||||
local mediaTable = lib.MediaTable
|
||||
local overrideMedia = lib.OverrideMedia
|
||||
|
||||
|
||||
-- create mediatype constants
|
||||
lib.MediaType.BACKGROUND = "background" -- background textures
|
||||
lib.MediaType.BORDER = "border" -- border textures
|
||||
lib.MediaType.FONT = "font" -- fonts
|
||||
lib.MediaType.STATUSBAR = "statusbar" -- statusbar textures
|
||||
lib.MediaType.SOUND = "sound" -- sound files
|
||||
|
||||
-- populate lib with default Blizzard data
|
||||
-- BACKGROUND
|
||||
if not lib.MediaTable.background then lib.MediaTable.background = {} end
|
||||
lib.MediaTable.background["None"] = [[]]
|
||||
lib.MediaTable.background["Blizzard Dialog Background"] = [[Interface\DialogFrame\UI-DialogBox-Background]]
|
||||
lib.MediaTable.background["Blizzard Dialog Background Dark"] = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]]
|
||||
lib.MediaTable.background["Blizzard Dialog Background Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]]
|
||||
lib.MediaTable.background["Blizzard Low Health"] = [[Interface\FullScreenTextures\LowHealth]]
|
||||
lib.MediaTable.background["Blizzard Marble"] = [[Interface\FrameGeneral\UI-Background-Marble]]
|
||||
lib.MediaTable.background["Blizzard Out of Control"] = [[Interface\FullScreenTextures\OutOfControl]]
|
||||
lib.MediaTable.background["Blizzard Parchment"] = [[Interface\AchievementFrame\UI-Achievement-Parchment-Horizontal]]
|
||||
lib.MediaTable.background["Blizzard Parchment 2"] = [[Interface\AchievementFrame\UI-GuildAchievement-Parchment-Horizontal]]
|
||||
lib.MediaTable.background["Blizzard Rock"] = [[Interface\FrameGeneral\UI-Background-Rock]]
|
||||
lib.MediaTable.background["Blizzard Tabard Background"] = [[Interface\TabardFrame\TabardFrameBackground]]
|
||||
lib.MediaTable.background["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Background]]
|
||||
lib.MediaTable.background["Solid"] = [[Interface\Buttons\WHITE8X8]]
|
||||
lib.DefaultMedia.background = "None"
|
||||
|
||||
-- BORDER
|
||||
if not lib.MediaTable.border then lib.MediaTable.border = {} end
|
||||
lib.MediaTable.border["None"] = [[]]
|
||||
lib.MediaTable.border["Blizzard Achievement Wood"] = [[Interface\AchievementFrame\UI-Achievement-WoodBorder]]
|
||||
lib.MediaTable.border["Blizzard Chat Bubble"] = [[Interface\Tooltips\ChatBubble-Backdrop]]
|
||||
lib.MediaTable.border["Blizzard Dialog"] = [[Interface\DialogFrame\UI-DialogBox-Border]]
|
||||
lib.MediaTable.border["Blizzard Dialog Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Border]]
|
||||
lib.MediaTable.border["Blizzard Party"] = [[Interface\CHARACTERFRAME\UI-Party-Border]]
|
||||
lib.MediaTable.border["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Border]]
|
||||
lib.DefaultMedia.border = "None"
|
||||
|
||||
-- FONT
|
||||
if not lib.MediaTable.font then lib.MediaTable.font = {} end
|
||||
local SML_MT_font = lib.MediaTable.font
|
||||
if locale == "koKR" then
|
||||
LOCALE_MASK = lib.LOCALE_BIT_koKR
|
||||
--
|
||||
SML_MT_font["굵은 글꼴"] = [[Fonts\2002B.TTF]]
|
||||
SML_MT_font["기본 글꼴"] = [[Fonts\2002.TTF]]
|
||||
SML_MT_font["데미지 글꼴"] = [[Fonts\K_Damage.TTF]]
|
||||
SML_MT_font["퀘스트 글꼴"] = [[Fonts\K_Pagetext.TTF]]
|
||||
--
|
||||
lib.DefaultMedia["font"] = "기본 글꼴" -- someone from koKR please adjust if needed
|
||||
--
|
||||
elseif locale == "zhCN" then
|
||||
LOCALE_MASK = lib.LOCALE_BIT_zhCN
|
||||
--
|
||||
SML_MT_font["伤害数字"] = [[Fonts\ZYKai_C.ttf]]
|
||||
SML_MT_font["默认"] = [[Fonts\ZYKai_T.ttf]]
|
||||
SML_MT_font["聊天"] = [[Fonts\ZYHei.ttf]]
|
||||
--
|
||||
lib.DefaultMedia["font"] = "默认" -- someone from zhCN please adjust if needed
|
||||
--
|
||||
elseif locale == "zhTW" then
|
||||
LOCALE_MASK = lib.LOCALE_BIT_zhTW
|
||||
--
|
||||
SML_MT_font["提示訊息"] = [[Fonts\bHEI00M.ttf]]
|
||||
SML_MT_font["聊天"] = [[Fonts\bHEI01B.ttf]]
|
||||
SML_MT_font["傷害數字"] = [[Fonts\bKAI00M.ttf]]
|
||||
SML_MT_font["預設"] = [[Fonts\bLEI00D.ttf]]
|
||||
--
|
||||
lib.DefaultMedia["font"] = "預設" -- someone from zhTW please adjust if needed
|
||||
|
||||
elseif locale == "ruRU" then
|
||||
LOCALE_MASK = lib.LOCALE_BIT_ruRU
|
||||
--
|
||||
SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]]
|
||||
SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT__.TTF]]
|
||||
SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS.TTF]]
|
||||
SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]]
|
||||
SML_MT_font["Skurri"] = [[Fonts\SKURRI.TTF]]
|
||||
--
|
||||
lib.DefaultMedia.font = "Arial Narrow"
|
||||
--
|
||||
else
|
||||
LOCALE_MASK = lib.LOCALE_BIT_western
|
||||
locale_is_western = true
|
||||
--
|
||||
SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]]
|
||||
SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT__.TTF]]
|
||||
SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS.TTF]]
|
||||
SML_MT_font["Skurri"] = [[Fonts\SKURRI.TTF]]
|
||||
--
|
||||
lib.DefaultMedia.font = "Friz Quadrata TT"
|
||||
--
|
||||
end
|
||||
|
||||
-- STATUSBAR
|
||||
if not lib.MediaTable.statusbar then lib.MediaTable.statusbar = {} end
|
||||
lib.MediaTable.statusbar["Blizzard"] = [[Interface\TargetingFrame\UI-StatusBar]]
|
||||
lib.MediaTable.statusbar["Blizzard Character Skills Bar"] = [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]]
|
||||
lib.DefaultMedia.statusbar = "Blizzard"
|
||||
|
||||
-- SOUND
|
||||
if not lib.MediaTable.sound then lib.MediaTable.sound = {} end
|
||||
lib.MediaTable.sound["None"] = [[Interface\Quiet.ogg]] -- Relies on the fact that PlaySound[File] doesn't error on these values.
|
||||
lib.DefaultMedia.sound = "None"
|
||||
|
||||
local function rebuildMediaList(mediatype)
|
||||
local mtable = mediaTable[mediatype]
|
||||
if not mtable then return end
|
||||
if not mediaList[mediatype] then mediaList[mediatype] = {} end
|
||||
local mlist = mediaList[mediatype]
|
||||
-- list can only get larger, so simply overwrite it
|
||||
local i = 0
|
||||
for k in pairs(mtable) do
|
||||
i = i + 1
|
||||
mlist[i] = k
|
||||
end
|
||||
table_sort(mlist)
|
||||
end
|
||||
|
||||
function lib:Register(mediatype, key, data, langmask)
|
||||
if type(mediatype) ~= "string" then
|
||||
error(MAJOR..":Register(mediatype, key, data, langmask) - mediatype must be string, got "..type(mediatype))
|
||||
end
|
||||
if type(key) ~= "string" then
|
||||
error(MAJOR..":Register(mediatype, key, data, langmask) - key must be string, got "..type(key))
|
||||
end
|
||||
mediatype = mediatype:lower()
|
||||
if mediatype == lib.MediaType.FONT and ((langmask and band(langmask, LOCALE_MASK) == 0) or not (langmask or locale_is_western)) then
|
||||
-- ignore fonts that aren't flagged as supporting local glyphs on non-western clients
|
||||
return false
|
||||
end
|
||||
if mediatype == lib.MediaType.SOUND and type(data) == "string" then
|
||||
local path = data:lower()
|
||||
if not path:find(".ogg", nil, true) and not path:find(".mp3", nil, true) and not path:find(".wav", nil, true) then
|
||||
-- Only wav, ogg and mp3 are valid sounds.
|
||||
return false
|
||||
end
|
||||
end
|
||||
if not mediaTable[mediatype] then mediaTable[mediatype] = {} end
|
||||
local mtable = mediaTable[mediatype]
|
||||
if mtable[key] then return false end
|
||||
|
||||
mtable[key] = data
|
||||
rebuildMediaList(mediatype)
|
||||
self.callbacks:Fire("LibSharedMedia_Registered", mediatype, key)
|
||||
return true
|
||||
end
|
||||
|
||||
function lib:Fetch(mediatype, key, noDefault)
|
||||
local mtt = mediaTable[mediatype]
|
||||
local overridekey = overrideMedia[mediatype]
|
||||
local result = mtt and ((overridekey and mtt[overridekey] or mtt[key]) or (not noDefault and defaultMedia[mediatype] and mtt[defaultMedia[mediatype]])) or nil
|
||||
return result ~= "" and result or nil
|
||||
end
|
||||
|
||||
function lib:IsValid(mediatype, key)
|
||||
return mediaTable[mediatype] and (not key or mediaTable[mediatype][key]) and true or false
|
||||
end
|
||||
|
||||
function lib:HashTable(mediatype)
|
||||
return mediaTable[mediatype]
|
||||
end
|
||||
|
||||
function lib:List(mediatype)
|
||||
if not mediaTable[mediatype] then
|
||||
return nil
|
||||
end
|
||||
if not mediaList[mediatype] then
|
||||
rebuildMediaList(mediatype)
|
||||
end
|
||||
return mediaList[mediatype]
|
||||
end
|
||||
|
||||
function lib:GetGlobal(mediatype)
|
||||
return overrideMedia[mediatype]
|
||||
end
|
||||
|
||||
function lib:SetGlobal(mediatype, key)
|
||||
if not mediaTable[mediatype] then
|
||||
return false
|
||||
end
|
||||
overrideMedia[mediatype] = (key and mediaTable[mediatype][key]) and key or nil
|
||||
self.callbacks:Fire("LibSharedMedia_SetGlobal", mediatype, overrideMedia[mediatype])
|
||||
return true
|
||||
end
|
||||
|
||||
function lib:GetDefault(mediatype)
|
||||
return defaultMedia[mediatype]
|
||||
end
|
||||
|
||||
function lib:SetDefault(mediatype, key)
|
||||
if mediaTable[mediatype] and mediaTable[mediatype][key] and not defaultMedia[mediatype] then
|
||||
defaultMedia[mediatype] = key
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,296 @@
|
||||
--[[---------------------------------------------------------------------------------
|
||||
General Library providing an alternate StartMoving() that allows you to
|
||||
specify a number of frames to snap-to when moving the frame around
|
||||
|
||||
Example Usage:
|
||||
|
||||
<OnLoad>
|
||||
this:RegisterForDrag("LeftButton")
|
||||
</OnLoad>
|
||||
<OnDragStart>
|
||||
StickyFrames:StartMoving(this, {WatchDogFrame_player, WatchDogFrame_target, WatchDogFrame_party1, WatchDogFrame_party2, WatchDogFrame_party3, WatchDogFrame_party4},3,3,3,3)
|
||||
</OnDragStart>
|
||||
<OnDragStop>
|
||||
StickyFrames:StopMoving(this)
|
||||
StickyFrames:AnchorFrame(this)
|
||||
</OnDragStop>
|
||||
|
||||
------------------------------------------------------------------------------------
|
||||
This is a modified version by Elv for ElvUI
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
local MAJOR, MINOR = "LibSimpleSticky-1.0", 2
|
||||
local StickyFrames = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not StickyFrames then return end
|
||||
|
||||
local twipe = table.wipe
|
||||
|
||||
local GetCursorPosition = GetCursorPosition
|
||||
local IsShiftKeyDown = IsShiftKeyDown
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
Class declaration, along with a temporary table to hold any existing OnUpdate
|
||||
scripts.
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
StickyFrames.scripts = StickyFrames.scripts or {}
|
||||
StickyFrames.rangeX = 15
|
||||
StickyFrames.rangeY = 15
|
||||
StickyFrames.sticky = StickyFrames.sticky or {}
|
||||
|
||||
local groupBlacklist = {}
|
||||
|
||||
local function isGroupPoint(frame, frame2)
|
||||
if groupBlacklist[frame2] then
|
||||
return true
|
||||
else
|
||||
local _, point = frame2:GetPoint()
|
||||
if groupBlacklist[point] or frame.parent == point then
|
||||
groupBlacklist[frame2.parent] = true
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
StickyFrames:StartMoving() - Sets a custom OnUpdate for the frame so it follows
|
||||
the mouse and snaps to the frames you specify
|
||||
|
||||
frame: The frame we want to move. Is typically "this"
|
||||
|
||||
frameList: A integer indexed list of frames that the given frame should try to
|
||||
stick to. These don't have to have anything special done to them,
|
||||
and they don't really even need to exist. You can inclue the
|
||||
moving frame in this list, it will be ignored. This helps you
|
||||
if you have a number of frames, just make ONE list to pass.
|
||||
|
||||
{WatchDogFrame_player, WatchDogFrame_party1, .. WatchDogFrame_party4}
|
||||
|
||||
left: If your frame has a tranparent border around the entire frame
|
||||
(think backdrops with borders). This can be used to fine tune the
|
||||
edges when you're stickying groups. Refers to any offset on the
|
||||
LEFT edge of the frame being moved.
|
||||
|
||||
top: same
|
||||
right: same
|
||||
bottom: same
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:StartMoving(frame, frameList, left, top, right, bottom)
|
||||
local x,y = GetCursorPosition()
|
||||
local aX,aY = frame:GetCenter()
|
||||
local aS = frame:GetEffectiveScale()
|
||||
|
||||
aX,aY = aX*aS,aY*aS
|
||||
local xoffset,yoffset = (aX - x),(aY - y)
|
||||
self.scripts[frame] = frame:GetScript("OnUpdate")
|
||||
frame:SetScript("OnUpdate", self:GetUpdateFunc(frame, frameList, xoffset, yoffset, left, top, right, bottom))
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
This stops the OnUpdate, leaving the frame at its last position. This will
|
||||
leave it anchored to UIParent. You can call StickyFrames:AnchorFrame() to
|
||||
anchor it back "TOPLEFT" , "TOPLEFT" to the parent.
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:StopMoving(frame)
|
||||
frame:SetScript("OnUpdate", self.scripts[frame])
|
||||
self.scripts[frame] = nil
|
||||
twipe(groupBlacklist)
|
||||
|
||||
if StickyFrames.sticky[frame] then
|
||||
local sticky = StickyFrames.sticky[frame]
|
||||
StickyFrames.sticky[frame] = nil
|
||||
return true, sticky
|
||||
else
|
||||
return false, nil
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
This can be called in conjunction with StickyFrames:StopMoving() to anchor the
|
||||
frame right back to the parent, so you can manipulate its children as a group
|
||||
(This is useful in WatchDog)
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:AnchorFrame(frame)
|
||||
local xA,yA = frame:GetCenter()
|
||||
local parent = frame:GetParent() or UIParent
|
||||
local xP,yP = parent:GetCenter()
|
||||
local sA,sP = frame:GetEffectiveScale(), parent:GetEffectiveScale()
|
||||
|
||||
xP,yP = (xP*sP) / sA, (yP*sP) / sA
|
||||
|
||||
local xo,yo = (xP - xA)*-1, (yP - yA)*-1
|
||||
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint("CENTER", parent, "CENTER", xo, yo)
|
||||
end
|
||||
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
Internal Functions -- Do not call these.
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
Returns an anonymous OnUpdate function for the frame in question. Need
|
||||
to provide the frame, frameList along with the x and y offset (difference between
|
||||
where the mouse picked up the frame, and the insets (left,top,right,bottom) in the
|
||||
case of borders, etc.w
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:GetUpdateFunc(frame, frameList, xoffset, yoffset, left, top, right, bottom)
|
||||
return function()
|
||||
local x,y = GetCursorPosition()
|
||||
local s = frame:GetEffectiveScale()
|
||||
|
||||
x,y = x/s,y/s
|
||||
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", x+xoffset, y+yoffset)
|
||||
|
||||
StickyFrames.sticky[frame] = nil
|
||||
for i = 1, #frameList do
|
||||
local v = frameList[i]
|
||||
if frame ~= v and frame ~= v:GetParent() and not isGroupPoint(frame, v) and not IsShiftKeyDown() and v:IsVisible() then
|
||||
if self:SnapFrame(frame, v, left, top, right, bottom) then
|
||||
StickyFrames.sticky[frame] = v
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
Internal debug function.
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:debug(msg)
|
||||
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00StickyFrames: |r"..tostring(msg))
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
This is called when finding an overlap between two sticky frame. If frameA is near
|
||||
a sticky edge of frameB, then it will snap to that edge and return true. If there
|
||||
is no sticky edge collision, will return false so we can test other frames for
|
||||
stickyness.
|
||||
------------------------------------------------------------------------------------]]
|
||||
function StickyFrames:SnapFrame(frameA, frameB, left, top, right, bottom)
|
||||
local sA, sB = frameA:GetEffectiveScale(), frameB:GetEffectiveScale()
|
||||
local xA, yA = frameA:GetCenter()
|
||||
local xB, yB = frameB:GetCenter()
|
||||
local hA = frameA:GetHeight() / 2
|
||||
local wA = frameA:GetWidth() / 2
|
||||
|
||||
local newX, newY = xA, yA
|
||||
|
||||
if not left then left = 0 end
|
||||
if not top then top = 0 end
|
||||
if not right then right = 0 end
|
||||
if not bottom then bottom = 0 end
|
||||
|
||||
-- Lets translate B's coords into A's scale
|
||||
if not xB or not yB or not sB or not sA or not sB then return end
|
||||
xB, yB = (xB*sB) / sA, (yB*sB) / sA
|
||||
|
||||
-- Grab the edges of each frame, for easier comparison
|
||||
|
||||
local lA, tA, rA, bA = frameA:GetLeft(), frameA:GetTop(), frameA:GetRight(), frameA:GetBottom()
|
||||
local lB, tB, rB, bB = frameB:GetLeft(), frameB:GetTop(), frameB:GetRight(), frameB:GetBottom()
|
||||
local snap = nil
|
||||
|
||||
-- Translate into A's scale
|
||||
lB, tB, rB, bB = (lB * sB) / sA, (tB * sB) / sA, (rB * sB) / sA, (bB * sB) / sA
|
||||
|
||||
if (bA <= tB and bB <= tA) then
|
||||
|
||||
-- Horizontal Centers
|
||||
if xA <= (xB + StickyFrames.rangeX) and xA >= (xB - StickyFrames.rangeX) then
|
||||
newX = xB
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Interior Left
|
||||
if lA <= (lB + StickyFrames.rangeX) and lA >= (lB - StickyFrames.rangeX) then
|
||||
newX = lB + wA
|
||||
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
|
||||
newX = newX + 4
|
||||
end
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Interior Right
|
||||
if rA <= (rB + StickyFrames.rangeX) and rA >= (rB - StickyFrames.rangeX) then
|
||||
newX = rB - wA
|
||||
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
|
||||
newX = newX - 4
|
||||
end
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Exterior Left to Right
|
||||
if lA <= (rB + StickyFrames.rangeX) and lA >= (rB - StickyFrames.rangeX) then
|
||||
newX = rB + (wA - left)
|
||||
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Exterior Right to Left
|
||||
if rA <= (lB + StickyFrames.rangeX) and rA >= (lB - StickyFrames.rangeX) then
|
||||
newX = lB - (wA - right)
|
||||
snap = true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if (lA <= rB and lB <= rA) then
|
||||
|
||||
-- Vertical Centers
|
||||
if yA <= (yB + StickyFrames.rangeY) and yA >= (yB - StickyFrames.rangeY) then
|
||||
newY = yB
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Interior Top
|
||||
if tA <= (tB + StickyFrames.rangeY) and tA >= (tB - StickyFrames.rangeY) then
|
||||
newY = tB - hA
|
||||
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
|
||||
newY = newY - 4
|
||||
end
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Interior Bottom
|
||||
if bA <= (bB + StickyFrames.rangeY) and bA >= (bB - StickyFrames.rangeY) then
|
||||
newY = bB + hA
|
||||
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
|
||||
newY = newY + 4
|
||||
end
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Exterior Top to Bottom
|
||||
if tA <= (bB + StickyFrames.rangeY + bottom) and tA >= (bB - StickyFrames.rangeY + bottom) then
|
||||
newY = bB - (hA - top)
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Exterior Bottom to Top
|
||||
if bA <= (tB + StickyFrames.rangeY - top) and bA >= (tB - StickyFrames.rangeY - top) then
|
||||
newY = tB + (hA - bottom)
|
||||
snap = true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if snap then
|
||||
frameA:ClearAllPoints()
|
||||
frameA:SetPoint("CENTER", UIParent, "BOTTOMLEFT", newX, newY)
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,235 @@
|
||||
--- = Background =
|
||||
-- Blizzard's IsSpellInRange API has always been very limited - you either must have the name of the spell, or its spell book ID. Checking directly by spellID is simply not possible.
|
||||
-- Now, in Mists of Pandaria, Blizzard changed the way that many talents and specialization spells work - instead of giving you a new spell when leaned, they replace existing spells. These replacement spells do not work with Blizzard's IsSpellInRange function whatsoever; this limitation is what prompted the creation of this lib.
|
||||
-- = Usage =
|
||||
-- **LibSpellRange-1.0** exposes an enhanced version of IsSpellInRange that:
|
||||
-- * Allows ranged checking based on both spell name and spellID.
|
||||
-- * Works correctly with replacement spells that will not work using Blizzard's IsSpellInRange method alone.
|
||||
--
|
||||
-- @class file
|
||||
-- @name LibSpellRange-1.0.lua
|
||||
|
||||
local major = "SpellRange-1.0"
|
||||
local minor = 19
|
||||
|
||||
assert(LibStub, format("%s requires LibStub.", major))
|
||||
|
||||
local Lib = LibStub:NewLibrary(major, minor)
|
||||
if not Lib then return end
|
||||
|
||||
local tonumber = _G.tonumber
|
||||
local strlower = _G.strlower
|
||||
local wipe = _G.wipe
|
||||
local type = _G.type
|
||||
|
||||
local GetSpellInfo = _G.GetSpellInfo
|
||||
local GetSpellLink = _G.GetSpellLink
|
||||
local GetSpellName = _G.GetSpellName
|
||||
local GetSpellTabInfo = _G.GetSpellTabInfo
|
||||
|
||||
local IsSpellInRange = _G.IsSpellInRange
|
||||
local SpellHasRange = _G.SpellHasRange
|
||||
|
||||
local MAX_SKILLLINE_TABS = _G.MAX_SKILLLINE_TABS
|
||||
|
||||
-- isNumber is basically a tonumber cache for maximum efficiency
|
||||
Lib.isNumber = Lib.isNumber or setmetatable({}, {
|
||||
__mode = "kv",
|
||||
__index = function(t, i)
|
||||
local o = tonumber(i) or false
|
||||
t[i] = o
|
||||
return o
|
||||
end})
|
||||
local isNumber = Lib.isNumber
|
||||
|
||||
-- strlower cache for maximum efficiency
|
||||
Lib.strlowerCache = Lib.strlowerCache or setmetatable(
|
||||
{}, {
|
||||
__index = function(t, i)
|
||||
if not i then return end
|
||||
local o
|
||||
if type(i) == "number" then
|
||||
o = i
|
||||
else
|
||||
o = strlower(i)
|
||||
end
|
||||
t[i] = o
|
||||
return o
|
||||
end,
|
||||
}) local strlowerCache = Lib.strlowerCache
|
||||
|
||||
-- Matches lowercase player spell names to their spellBookID
|
||||
Lib.spellsByName_spell = Lib.spellsByName_spell or {}
|
||||
local spellsByName_spell = Lib.spellsByName_spell
|
||||
|
||||
-- Matches player spellIDs to their spellBookID
|
||||
Lib.spellsByID_spell = Lib.spellsByID_spell or {}
|
||||
local spellsByID_spell = Lib.spellsByID_spell
|
||||
|
||||
-- Matches lowercase pet spell names to their spellBookID
|
||||
Lib.spellsByName_pet = Lib.spellsByName_pet or {}
|
||||
local spellsByName_pet = Lib.spellsByName_pet
|
||||
|
||||
-- Matches pet spellIDs to their spellBookID
|
||||
Lib.spellsByID_pet = Lib.spellsByID_pet or {}
|
||||
local spellsByID_pet = Lib.spellsByID_pet
|
||||
|
||||
local blacklistedIDs = {}
|
||||
|
||||
-- Updates spellsByName and spellsByID
|
||||
local function UpdateBook(bookType)
|
||||
local _, offs, numspells
|
||||
local max = 0
|
||||
|
||||
for i = MAX_SKILLLINE_TABS, 1, -1 do
|
||||
_, _, offs, numspells = GetSpellTabInfo(i)
|
||||
|
||||
if numspells > 0 then
|
||||
max = offs + numspells
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local spellsByName = Lib["spellsByName_" .. bookType]
|
||||
local spellsByID = Lib["spellsByID_" .. bookType]
|
||||
|
||||
wipe(spellsByName)
|
||||
wipe(spellsByID)
|
||||
wipe(blacklistedIDs)
|
||||
|
||||
for spellBookID = 1, max do
|
||||
local spellName, rank = GetSpellName(spellBookID, bookType)
|
||||
|
||||
if spellName and (rank == "" or rank:match("%d+")) then
|
||||
local link = GetSpellLink(spellName, rank)
|
||||
local spellID = tonumber(link and link:gsub("|", "||"):match("spell:(%d+)"))
|
||||
|
||||
if spellName then
|
||||
spellsByName[strlower(spellName)] = spellBookID
|
||||
end
|
||||
|
||||
if spellID then
|
||||
spellsByID[spellID] = spellBookID
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Handles updating spellsByName and spellsByID
|
||||
if not Lib.updaterFrame then
|
||||
Lib.updaterFrame = CreateFrame("Frame")
|
||||
end
|
||||
Lib.updaterFrame:UnregisterAllEvents()
|
||||
Lib.updaterFrame:RegisterEvent("LEARNED_SPELL_IN_TAB")
|
||||
Lib.updaterFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
|
||||
local function UpdateSpells(_, event)
|
||||
UpdateBook("spell")
|
||||
UpdateBook("pet")
|
||||
if event == "PLAYER_ENTERING_WORLD" then
|
||||
Lib.updaterFrame:UnregisterEvent(event)
|
||||
end
|
||||
end
|
||||
|
||||
Lib.updaterFrame:SetScript("OnEvent", UpdateSpells)
|
||||
UpdateSpells()
|
||||
|
||||
--- Improved spell range checking function.
|
||||
-- @name SpellRange.IsSpellInRange
|
||||
-- @paramsig spell, unit
|
||||
-- @param spell Name or spellID of a spell that you wish to check the range of. The spell must be a spell that you have in your spellbook or your pet's spellbook.
|
||||
-- @param unit UnitID of the spell that you wish to check the range on.
|
||||
-- @return Exact same returns as http://wowprogramming.com/docs/api/IsSpellInRange
|
||||
-- @usage
|
||||
-- -- Check spell range by spell name on unit "target"
|
||||
-- local SpellRange = LibStub("SpellRange-1.0")
|
||||
-- local inRange = SpellRange.IsSpellInRange("Stormstrike", "target")
|
||||
--
|
||||
-- -- Check spell range by spellID on unit "mouseover"
|
||||
-- local SpellRange = LibStub("SpellRange-1.0")
|
||||
-- local inRange = SpellRange.IsSpellInRange(17364, "mouseover")
|
||||
function Lib.IsSpellInRange(spellInput, unit)
|
||||
if isNumber[spellInput] then
|
||||
local spell = spellsByID_spell[spellInput]
|
||||
if spell then
|
||||
return IsSpellInRange(spell, "spell", unit)
|
||||
else
|
||||
spell = spellsByID_pet[spellInput]
|
||||
if spell then
|
||||
return IsSpellInRange(spell, "pet", unit)
|
||||
elseif not blacklistedIDs[spellInput] then
|
||||
spell = GetSpellInfo(spellInput)
|
||||
if spell then
|
||||
spell = strlowerCache[spell]
|
||||
if spellsByName_spell[spell] then
|
||||
local spellBookID = spellsByName_spell[spell]
|
||||
Lib["spellsByID_spell"][spellInput] = spellBookID
|
||||
return IsSpellInRange(spellBookID, "spell", unit)
|
||||
elseif spellsByName_pet[spell] then
|
||||
local spellBookID = spellsByName_pet[spell]
|
||||
Lib["spellsByID_pet"][spellInput] = spellBookID
|
||||
return IsSpellInRange(spellBookID, "pet", unit)
|
||||
end
|
||||
end
|
||||
|
||||
blacklistedIDs[spellInput] = true
|
||||
return
|
||||
end
|
||||
end
|
||||
else
|
||||
spellInput = strlowerCache[spellInput]
|
||||
|
||||
local spell = spellsByName_spell[spellInput]
|
||||
if spell then
|
||||
return IsSpellInRange(spell, "spell", unit)
|
||||
else
|
||||
spell = spellsByName_pet[spellInput]
|
||||
if spell then
|
||||
return IsSpellInRange(spell, "pet", unit)
|
||||
end
|
||||
end
|
||||
|
||||
return IsSpellInRange(spellInput, unit)
|
||||
end
|
||||
end
|
||||
|
||||
--- Improved SpellHasRange.
|
||||
-- @name SpellRange.SpellHasRange
|
||||
-- @paramsig spell
|
||||
-- @param spell Name or spellID of a spell that you wish to check for a range. The spell must be a spell that you have in your spellbook or your pet's spellbook.
|
||||
-- @return Exact same returns as http://wowprogramming.com/docs/api/SpellHasRange
|
||||
-- @usage
|
||||
-- -- Check if a spell has a range by spell name
|
||||
-- local SpellRange = LibStub("SpellRange-1.0")
|
||||
-- local hasRange = SpellRange.SpellHasRange("Stormstrike")
|
||||
--
|
||||
-- -- Check if a spell has a range by spellID
|
||||
-- local SpellRange = LibStub("SpellRange-1.0")
|
||||
-- local hasRange = SpellRange.SpellHasRange(17364)
|
||||
function Lib.SpellHasRange(spellInput)
|
||||
if isNumber[spellInput] then
|
||||
local spell = spellsByID_spell[spellInput]
|
||||
if spell then
|
||||
return SpellHasRange(spell, "spell")
|
||||
else
|
||||
spell = spellsByID_pet[spellInput]
|
||||
if spell then
|
||||
return SpellHasRange(spell, "pet")
|
||||
end
|
||||
end
|
||||
else
|
||||
spellInput = strlowerCache[spellInput]
|
||||
|
||||
local spell = spellsByName_spell[spellInput]
|
||||
if spell then
|
||||
return SpellHasRange(spell, "spell")
|
||||
else
|
||||
spell = spellsByName_pet[spellInput]
|
||||
if spell then
|
||||
return SpellHasRange(spell, "pet")
|
||||
end
|
||||
end
|
||||
|
||||
return SpellHasRange(spellInput)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,113 @@
|
||||
local MAJOR_VERSION = "LibTranslit-1.0"
|
||||
local MINOR_VERSION = 3
|
||||
if not LibStub then
|
||||
error(MAJOR_VERSION .. " requires LibStub.")
|
||||
end
|
||||
local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
|
||||
if not lib then
|
||||
return
|
||||
end
|
||||
|
||||
local CyrToLat = {
|
||||
["А"] = "A",
|
||||
["а"] = "a",
|
||||
["Б"] = "B",
|
||||
["б"] = "b",
|
||||
["В"] = "V",
|
||||
["в"] = "v",
|
||||
["Г"] = "G",
|
||||
["г"] = "g",
|
||||
["Д"] = "D",
|
||||
["д"] = "d",
|
||||
["Е"] = "E",
|
||||
["е"] = "e",
|
||||
["Ё"] = "e",
|
||||
["ё"] = "e",
|
||||
["Ж"] = "Zh",
|
||||
["ж"] = "zh",
|
||||
["З"] = "Z",
|
||||
["з"] = "z",
|
||||
["И"] = "I",
|
||||
["и"] = "i",
|
||||
["Й"] = "Y",
|
||||
["й"] = "y",
|
||||
["К"] = "K",
|
||||
["к"] = "k",
|
||||
["Л"] = "L",
|
||||
["л"] = "l",
|
||||
["М"] = "M",
|
||||
["м"] = "m",
|
||||
["Н"] = "N",
|
||||
["н"] = "n",
|
||||
["О"] = "O",
|
||||
["о"] = "o",
|
||||
["П"] = "P",
|
||||
["п"] = "p",
|
||||
["Р"] = "R",
|
||||
["р"] = "r",
|
||||
["С"] = "S",
|
||||
["с"] = "s",
|
||||
["Т"] = "T",
|
||||
["т"] = "t",
|
||||
["У"] = "U",
|
||||
["у"] = "u",
|
||||
["Ф"] = "F",
|
||||
["ф"] = "f",
|
||||
["Х"] = "Kh",
|
||||
["х"] = "kh",
|
||||
["Ц"] = "Ts",
|
||||
["ц"] = "ts",
|
||||
["Ч"] = "Ch",
|
||||
["ч"] = "ch",
|
||||
["Ш"] = "Sh",
|
||||
["ш"] = "sh",
|
||||
["Щ"] = "Shch",
|
||||
["щ"] = "shch",
|
||||
["Ъ"] = "",
|
||||
["ъ"] = "",
|
||||
["Ы"] = "Y",
|
||||
["ы"] = "y",
|
||||
["Ь"] = "",
|
||||
["ь"] = "",
|
||||
["Э"] = "E",
|
||||
["э"] = "e",
|
||||
["Ю"] = "Yu",
|
||||
["ю"] = "yu",
|
||||
["Я"] = "Ya",
|
||||
["я"] = "ya"
|
||||
}
|
||||
|
||||
function lib:Transliterate(str, mark)
|
||||
if not str then
|
||||
return ""
|
||||
end
|
||||
|
||||
local mark = mark or ""
|
||||
local tstr = ""
|
||||
local marked = false
|
||||
local i = 1
|
||||
|
||||
while i <= string.len(str) do
|
||||
local c = str:sub(i, i)
|
||||
local b = string.byte(c)
|
||||
|
||||
if b == 208 or b == 209 then
|
||||
if marked == false then
|
||||
tstr = tstr .. mark
|
||||
marked = true
|
||||
end
|
||||
c = str:sub(i + 1, i + 1)
|
||||
tstr = tstr .. (CyrToLat[string.char(b, string.byte(c))] or string.char(b, string.byte(c)))
|
||||
|
||||
i = i + 2
|
||||
else
|
||||
if c == " " or c == "-" then
|
||||
marked = false
|
||||
end
|
||||
tstr = tstr .. c
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
return tstr
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||
<Script file="Ace3\LibStub\LibStub.lua"/>
|
||||
<Script file="Ace3\CallbackHandler-1.0\CallbackHandler-1.0.lua"/>
|
||||
<Include file="Ace3\AceAddon-3.0\AceAddon-3.0.xml"/>
|
||||
<Include file="Ace3\AceEvent-3.0\AceEvent-3.0.xml"/>
|
||||
<Include file="Ace3\AceTimer-3.0\AceTimer-3.0.xml"/>
|
||||
<Include file="Ace3\AceHook-3.0\AceHook-3.0.xml"/>
|
||||
<Include file="Ace3\AceDB-3.0\AceDB-3.0.xml"/>
|
||||
<Include file="Ace3\AceLocale-3.0\AceLocale-3.0.xml"/>
|
||||
<Include file="Ace3\AceConsole-3.0\AceConsole-3.0.xml"/>
|
||||
<Include file="Ace3\AceComm-3.0\AceComm-3.0.xml"/>
|
||||
<Include file="Ace3\AceSerializer-3.0\AceSerializer-3.0.xml"/>
|
||||
<Script file="LibSharedMedia-3.0\LibSharedMedia-3.0.lua"/>
|
||||
<Script file="LibSimpleSticky\LibSimpleSticky.lua"/>
|
||||
<Script file="LibSpellRange-1.0\LibSpellRange-1.0.lua"/>
|
||||
<Script file="HealPredict\healpredict.lua"/>
|
||||
<Include file="oUF\oUF.xml"/>
|
||||
<Include file="oUF_Plugins\oUF_Plugins.xml"/>
|
||||
<Script file="LibDataBroker\LibDataBroker-1.1.lua"/>
|
||||
<Script file="LibDualSpec-1.0\LibDualSpec-1.0.lua"/>
|
||||
<Script file="LibElvUIPlugin-1.0\LibElvUIPlugin-1.0.lua"/>
|
||||
<Include file="UTF8\UTF8.xml"/>
|
||||
<Include file="LibItemSearch-1.2\LibItemSearch-1.2.xml"/>
|
||||
<Script file="LibChatAnims\LibChatAnims.lua"/>
|
||||
<Script file="LibCompress\LibCompress.lua"/>
|
||||
<Script file="LibBase64-1.0\LibBase64-1.0.lua"/>
|
||||
<Script file="LibAnim\LibAnim.lua"/>
|
||||
<Script file="LibActionButton-1.0\LibActionButton-1.0.lua"/>
|
||||
<Include file="LibAuraInfo-1.0\lib.xml"/>
|
||||
<Script file="LibTranslit-1.0\LibTranslit-1.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,5 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="utf8data.lua"/>
|
||||
<Script file="utf8.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,318 @@
|
||||
-- $Id: utf8.lua 179 2009-04-03 18:10:03Z pasta $
|
||||
--
|
||||
-- Provides UTF-8 aware string functions implemented in pure lua:
|
||||
-- * string.utf8len(s)
|
||||
-- * string.utf8sub(s, i, j)
|
||||
-- * string.utf8reverse(s)
|
||||
--
|
||||
-- If utf8data.lua (containing the lower<->upper case mappings) is loaded, these
|
||||
-- additional functions are available:
|
||||
-- * string.utf8upper(s)
|
||||
-- * string.utf8lower(s)
|
||||
--
|
||||
-- All functions behave as their non UTF-8 aware counterparts with the exception
|
||||
-- that UTF-8 characters are used instead of bytes for all units.
|
||||
|
||||
--[[
|
||||
Copyright (c) 2006-2007, Kyle Smith
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
--]]
|
||||
|
||||
-- ABNF from RFC 3629
|
||||
--
|
||||
-- UTF8-octets = *( UTF8-char )
|
||||
-- UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
|
||||
-- UTF8-1 = %x00-7F
|
||||
-- UTF8-2 = %xC2-DF UTF8-tail
|
||||
-- UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
|
||||
-- %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
|
||||
-- UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
|
||||
-- %xF4 %x80-8F 2( UTF8-tail )
|
||||
-- UTF8-tail = %x80-BF
|
||||
--
|
||||
|
||||
local strbyte, strlen, strsub, type = string.byte, string.len, string.sub, type
|
||||
|
||||
-- returns the number of bytes used by the UTF-8 character at byte i in s
|
||||
-- also doubles as a UTF-8 character validator
|
||||
local function utf8charbytes(s, i)
|
||||
-- argument defaults
|
||||
i = i or 1
|
||||
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8charbytes' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
if type(i) ~= "number" then
|
||||
error("bad argument #2 to 'utf8charbytes' (number expected, got ".. type(i).. ")")
|
||||
end
|
||||
|
||||
local c = strbyte(s, i)
|
||||
|
||||
-- determine bytes needed for character, based on RFC 3629
|
||||
-- validate byte 1
|
||||
if c > 0 and c <= 127 then
|
||||
-- UTF8-1
|
||||
return 1
|
||||
|
||||
elseif c >= 194 and c <= 223 then
|
||||
-- UTF8-2
|
||||
local c2 = strbyte(s, i + 1)
|
||||
|
||||
if not c2 then
|
||||
error("UTF-8 string terminated early")
|
||||
end
|
||||
|
||||
-- validate byte 2
|
||||
if c2 < 128 or c2 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
return 2
|
||||
|
||||
elseif c >= 224 and c <= 239 then
|
||||
-- UTF8-3
|
||||
local c2 = strbyte(s, i + 1)
|
||||
local c3 = strbyte(s, i + 2)
|
||||
|
||||
if not c2 or not c3 then
|
||||
error("UTF-8 string terminated early")
|
||||
end
|
||||
|
||||
-- validate byte 2
|
||||
if c == 224 and (c2 < 160 or c2 > 191) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c == 237 and (c2 < 128 or c2 > 159) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c2 < 128 or c2 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
-- validate byte 3
|
||||
if c3 < 128 or c3 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
return 3
|
||||
|
||||
elseif c >= 240 and c <= 244 then
|
||||
-- UTF8-4
|
||||
local c2 = strbyte(s, i + 1)
|
||||
local c3 = strbyte(s, i + 2)
|
||||
local c4 = strbyte(s, i + 3)
|
||||
|
||||
if not c2 or not c3 or not c4 then
|
||||
error("UTF-8 string terminated early")
|
||||
end
|
||||
|
||||
-- validate byte 2
|
||||
if c == 240 and (c2 < 144 or c2 > 191) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c == 244 and (c2 < 128 or c2 > 143) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c2 < 128 or c2 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
-- validate byte 3
|
||||
if c3 < 128 or c3 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
-- validate byte 4
|
||||
if c4 < 128 or c4 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
return 4
|
||||
|
||||
else
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
end
|
||||
|
||||
-- returns the number of characters in a UTF-8 string
|
||||
local function utf8len(s)
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8len' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local bytes = strlen(s)
|
||||
local len = 0
|
||||
|
||||
while pos <= bytes do
|
||||
len = len + 1
|
||||
pos = pos + utf8charbytes(s, pos)
|
||||
end
|
||||
|
||||
return len
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8len then
|
||||
string.utf8len = utf8len
|
||||
end
|
||||
|
||||
-- functions identically to string.sub except that i and j are UTF-8 characters
|
||||
-- instead of bytes
|
||||
local function utf8sub(s, i, j)
|
||||
-- argument defaults
|
||||
j = j or -1
|
||||
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8sub' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
if type(i) ~= "number" then
|
||||
error("bad argument #2 to 'utf8sub' (number expected, got ".. type(i).. ")")
|
||||
end
|
||||
if type(j) ~= "number" then
|
||||
error("bad argument #3 to 'utf8sub' (number expected, got ".. type(j).. ")")
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local bytes = strlen(s)
|
||||
local len = 0
|
||||
|
||||
-- only set l if i or j is negative
|
||||
local l = (i >= 0 and j >= 0) or utf8len(s)
|
||||
local startChar = (i >= 0) and i or l + i + 1
|
||||
local endChar = (j >= 0) and j or l + j + 1
|
||||
|
||||
-- can't have start before end!
|
||||
if startChar > endChar then
|
||||
return ""
|
||||
end
|
||||
|
||||
-- byte offsets to pass to string.sub
|
||||
local startByte, endByte = 1, bytes
|
||||
|
||||
while pos <= bytes do
|
||||
len = len + 1
|
||||
|
||||
if len == startChar then
|
||||
startByte = pos
|
||||
end
|
||||
|
||||
pos = pos + utf8charbytes(s, pos)
|
||||
|
||||
if len == endChar then
|
||||
endByte = pos - 1
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return strsub(s, startByte, endByte)
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8sub then
|
||||
string.utf8sub = utf8sub
|
||||
end
|
||||
|
||||
-- replace UTF-8 characters based on a mapping table
|
||||
local function utf8replace(s, mapping)
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8replace' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
if type(mapping) ~= "table" then
|
||||
error("bad argument #2 to 'utf8replace' (table expected, got ".. type(mapping).. ")")
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local bytes = strlen(s)
|
||||
local charbytes
|
||||
local newstr = ""
|
||||
|
||||
while pos <= bytes do
|
||||
charbytes = utf8charbytes(s, pos)
|
||||
local c = strsub(s, pos, pos + charbytes - 1)
|
||||
|
||||
newstr = newstr .. (mapping[c] or c)
|
||||
|
||||
pos = pos + charbytes
|
||||
end
|
||||
|
||||
return newstr
|
||||
end
|
||||
|
||||
-- identical to string.upper except it knows about unicode simple case conversions
|
||||
local function utf8upper(s)
|
||||
return utf8replace(s, utf8_lc_uc)
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8upper and utf8_lc_uc then
|
||||
string.utf8upper = utf8upper
|
||||
end
|
||||
|
||||
-- identical to string.lower except it knows about unicode simple case conversions
|
||||
local function utf8lower(s)
|
||||
return utf8replace(s, utf8_uc_lc)
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8lower and utf8_uc_lc then
|
||||
string.utf8lower = utf8lower
|
||||
end
|
||||
|
||||
-- identical to string.reverse except that it supports UTF-8
|
||||
local function utf8reverse(s)
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8reverse' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
|
||||
local bytes = strlen(s)
|
||||
local pos = bytes
|
||||
local charbytes
|
||||
local newstr = ""
|
||||
local c
|
||||
|
||||
while pos > 0 do
|
||||
c = strbyte(s, pos)
|
||||
while c >= 128 and c <= 191 do
|
||||
pos = pos - 1
|
||||
c = strbyte(pos)
|
||||
end
|
||||
|
||||
charbytes = utf8charbytes(s, pos)
|
||||
|
||||
newstr = newstr .. strsub(s, pos, pos + charbytes - 1)
|
||||
|
||||
pos = pos - 1
|
||||
end
|
||||
|
||||
return newstr
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8reverse then
|
||||
string.utf8reverse = utf8reverse
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2006-2017 Trond A Ekseth <troeks@gmail.com>
|
||||
Copyright (c) 2016-2017 Val Voronov <i.lightspark@gmail.com>
|
||||
Copyright (c) 2016-2017 Adrian L Lange <contact@p3lim.net>
|
||||
Copyright (c) 2016-2017 Rainrider <rainrider.wow@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,112 @@
|
||||
local parent, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
-- sourced from Blizzard_ArenaUI/Blizzard_ArenaUI.lua
|
||||
local MAX_ARENA_ENEMIES = MAX_ARENA_ENEMIES or 5
|
||||
|
||||
-- sourced from FrameXML/TargetFrame.lua
|
||||
local MAX_BOSS_FRAMES = MAX_BOSS_FRAMES or 4
|
||||
|
||||
-- sourced from FrameXML/PartyMemberFrame.lua
|
||||
local MAX_PARTY_MEMBERS = MAX_PARTY_MEMBERS or 4
|
||||
|
||||
local hiddenParent = CreateFrame('Frame', nil, UIParent)
|
||||
hiddenParent:SetAllPoints()
|
||||
hiddenParent:Hide()
|
||||
|
||||
local function handleFrame(baseName)
|
||||
local frame
|
||||
if(type(baseName) == 'string') then
|
||||
frame = _G[baseName]
|
||||
else
|
||||
frame = baseName
|
||||
end
|
||||
|
||||
if(frame) then
|
||||
frame:UnregisterAllEvents()
|
||||
frame:Hide()
|
||||
|
||||
-- Keep frame hidden without causing taint
|
||||
frame:SetParent(hiddenParent)
|
||||
|
||||
local health = frame.healthBar or frame.healthbar
|
||||
if(health) then
|
||||
health:UnregisterAllEvents()
|
||||
end
|
||||
|
||||
local power = frame.manabar
|
||||
if(power) then
|
||||
power:UnregisterAllEvents()
|
||||
end
|
||||
|
||||
local spell = frame.castBar or frame.spellbar
|
||||
if(spell) then
|
||||
spell:UnregisterAllEvents()
|
||||
end
|
||||
|
||||
local buffFrame = frame.BuffFrame
|
||||
if(buffFrame) then
|
||||
buffFrame:UnregisterAllEvents()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function oUF:DisableBlizzard(unit)
|
||||
if(not unit) then return end
|
||||
|
||||
if(unit == 'player') then
|
||||
handleFrame(PlayerFrame)
|
||||
|
||||
-- For the damn vehicle support:
|
||||
PlayerFrame:RegisterEvent('PLAYER_ENTERING_WORLD')
|
||||
PlayerFrame:RegisterEvent('UNIT_ENTERING_VEHICLE')
|
||||
PlayerFrame:RegisterEvent('UNIT_ENTERED_VEHICLE')
|
||||
PlayerFrame:RegisterEvent('UNIT_EXITING_VEHICLE')
|
||||
PlayerFrame:RegisterEvent('UNIT_EXITED_VEHICLE')
|
||||
|
||||
-- User placed frames don't animate
|
||||
PlayerFrame:SetUserPlaced(true)
|
||||
PlayerFrame:SetDontSavePosition(true)
|
||||
elseif(unit == 'pet') then
|
||||
handleFrame(PetFrame)
|
||||
elseif(unit == 'target') then
|
||||
handleFrame(TargetFrame)
|
||||
handleFrame(ComboFrame)
|
||||
elseif(unit == 'focus') then
|
||||
handleFrame(FocusFrame)
|
||||
handleFrame(TargetofFocusFrame)
|
||||
elseif(unit == 'targettarget') then
|
||||
handleFrame(TargetFrameToT)
|
||||
elseif(unit:match('boss%d?$')) then
|
||||
local id = unit:match('boss(%d)')
|
||||
if(id) then
|
||||
handleFrame('Boss' .. id .. 'TargetFrame')
|
||||
else
|
||||
for i = 1, MAX_BOSS_FRAMES do
|
||||
handleFrame(string.format('Boss%dTargetFrame', i))
|
||||
end
|
||||
end
|
||||
elseif(unit:match('party%d?$')) then
|
||||
local id = unit:match('party(%d)')
|
||||
if(id) then
|
||||
handleFrame('PartyMemberFrame' .. id)
|
||||
else
|
||||
for i = 1, MAX_PARTY_MEMBERS do
|
||||
handleFrame(string.format('PartyMemberFrame%d', i))
|
||||
end
|
||||
end
|
||||
elseif(unit:match('arena%d?$')) then
|
||||
local id = unit:match('arena(%d)')
|
||||
if(id) then
|
||||
handleFrame('ArenaEnemyFrame' .. id)
|
||||
else
|
||||
for i = 1, MAX_ARENA_ENEMIES do
|
||||
handleFrame(string.format('ArenaEnemyFrame%d', i))
|
||||
end
|
||||
end
|
||||
|
||||
-- Blizzard_ArenaUI should not be loaded
|
||||
Arena_LoadUI = function() end
|
||||
SetCVar('showArenaEnemyFrames', '0', 'SHOW_ARENA_ENEMY_FRAMES_TEXT')
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,212 @@
|
||||
local parent, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local frame_metatable = Private.frame_metatable
|
||||
|
||||
local colors = {
|
||||
smooth = {
|
||||
1, 0, 0,
|
||||
1, 1, 0,
|
||||
0, 1, 0
|
||||
},
|
||||
health = {49 / 255, 207 / 255, 37 / 255},
|
||||
disconnected = {.6, .6, .6},
|
||||
tapped = {.6, .6, .6},
|
||||
threshold_20 = {1, 0, 0},
|
||||
threshold_35 = {1, 0, 0.8},
|
||||
threshold_50 = {1, 0.5, 0},
|
||||
threshold_75 = {1, 1, 0},
|
||||
runes = {
|
||||
{1, 0, 0}, -- blood
|
||||
{0, 0.5, 0}, -- unholy
|
||||
{0, 1, 1}, -- frost
|
||||
{0.9, 0.1, 1}, -- death
|
||||
},
|
||||
class = {},
|
||||
debuff = {},
|
||||
reaction = {},
|
||||
power = {},
|
||||
threat = {},
|
||||
}
|
||||
|
||||
for debuffType, color in next, DebuffTypeColor do
|
||||
colors.debuff[debuffType] = {color.r, color.g, color.b}
|
||||
end
|
||||
|
||||
for eclass, color in next, FACTION_BAR_COLORS do
|
||||
colors.reaction[eclass] = {color.r, color.g, color.b}
|
||||
end
|
||||
|
||||
for power, color in next, PowerBarColor do
|
||||
if (type(power) == 'string') then
|
||||
if(type(select(2, next(color))) == 'table') then
|
||||
colors.power[power] = {}
|
||||
|
||||
for index, color in next, color do
|
||||
colors.power[power][index] = {color.r, color.g, color.b}
|
||||
end
|
||||
else
|
||||
colors.power[power] = {color.r, color.g, color.b, atlas = color.atlas}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- sourced from FrameXML/Constants.lua
|
||||
colors.power[0] = colors.power.MANA
|
||||
colors.power[1] = colors.power.RAGE
|
||||
colors.power[2] = colors.power.FOCUS
|
||||
colors.power[3] = colors.power.ENERGY
|
||||
colors.power[4] = colors.power.HAPPINESS
|
||||
colors.power[5] = colors.power.RUNES
|
||||
colors.power[6] = colors.power.RUNIC_POWER
|
||||
|
||||
for i = 0, 3 do
|
||||
colors.threat[i] = {GetThreatStatusColor(i)}
|
||||
end
|
||||
|
||||
local function colorsAndPercent(a, b, ...)
|
||||
if(a <= 0 or b == 0) then
|
||||
return nil, ...
|
||||
elseif(a >= b) then
|
||||
return nil, select(-3, ...)
|
||||
end
|
||||
|
||||
local num = select('#', ...) / 3
|
||||
local segment, relperc = math.modf((a / b) * (num - 1))
|
||||
return relperc, select((segment * 3) + 1, ...)
|
||||
end
|
||||
|
||||
-- http://www.wowwiki.com/ColorGradient
|
||||
--[[ Colors: oUF:RGBColorGradient(a, b, ...)
|
||||
Used to convert a percent value (the quotient of `a` and `b`) into a gradient from 2 or more RGB colors. If more than 2
|
||||
colors are passed, the gradient will be between the two colors which perc lies in an evenly divided range. A RGB color
|
||||
is a sequence of 3 consecutive RGB percent values (in the range [0-1]). If `a` is negative or `b` is zero then the first
|
||||
RGB color (the first 3 RGB values passed to the function) is returned. If `a` is bigger than or equal to `b`, then the
|
||||
last 3 RGB values are returned.
|
||||
|
||||
* self - the global oUF object
|
||||
* a - value used as numerator to calculate the percentage (number)
|
||||
* b - value used as denominator to calculate the percentage (number)
|
||||
* ... - a list of RGB percent values. At least 6 values should be passed (number [0-1])
|
||||
--]]
|
||||
function oUF:RGBColorGradient(...)
|
||||
local relperc, r1, g1, b1, r2, g2, b2 = colorsAndPercent(...)
|
||||
if(relperc) then
|
||||
return r1 + (r2 - r1) * relperc, g1 + (g2 - g1) * relperc, b1 + (b2 - b1) * relperc
|
||||
else
|
||||
return r1, g1, b1
|
||||
end
|
||||
end
|
||||
|
||||
-- HCY functions are based on http://www.chilliant.com/rgb2hsv.html
|
||||
local function getY(r, g, b)
|
||||
return 0.299 * r + 0.587 * g + 0.114 * b
|
||||
end
|
||||
|
||||
local function rgbToHCY(r, g, b)
|
||||
local min, max = math.min(r, g, b), math.max(r, g, b)
|
||||
local chroma = max - min
|
||||
local hue
|
||||
if(chroma > 0) then
|
||||
if(r == max) then
|
||||
hue = ((g - b) / chroma) % 6
|
||||
elseif(g == max) then
|
||||
hue = (b - r) / chroma + 2
|
||||
elseif(b == max) then
|
||||
hue = (r - g) / chroma + 4
|
||||
end
|
||||
hue = hue / 6
|
||||
end
|
||||
return hue, chroma, getY(r, g, b)
|
||||
end
|
||||
|
||||
local function hcyToRGB(hue, chroma, luma)
|
||||
local r, g, b = 0, 0, 0
|
||||
if(hue and luma > 0) then
|
||||
local h2 = hue * 6
|
||||
local x = chroma * (1 - math.abs(h2 % 2 - 1))
|
||||
if(h2 < 1) then
|
||||
r, g, b = chroma, x, 0
|
||||
elseif(h2 < 2) then
|
||||
r, g, b = x, chroma, 0
|
||||
elseif(h2 < 3) then
|
||||
r, g, b = 0, chroma, x
|
||||
elseif(h2 < 4) then
|
||||
r, g, b = 0, x, chroma
|
||||
elseif(h2 < 5) then
|
||||
r, g, b = x, 0, chroma
|
||||
else
|
||||
r, g, b = chroma, 0, x
|
||||
end
|
||||
|
||||
local y = getY(r, g, b)
|
||||
if(luma < y) then
|
||||
chroma = chroma * (luma / y)
|
||||
elseif(y < 1) then
|
||||
chroma = chroma * (1 - luma) / (1 - y)
|
||||
end
|
||||
|
||||
r = (r - y) * chroma + luma
|
||||
g = (g - y) * chroma + luma
|
||||
b = (b - y) * chroma + luma
|
||||
end
|
||||
return r, g, b
|
||||
end
|
||||
|
||||
--[[ Colors: oUF:HCYColorGradient(a, b, ...)
|
||||
Used to convert a percent value (the quotient of `a` and `b`) into a gradient from 2 or more HCY colors. If more than 2
|
||||
colors are passed, the gradient will be between the two colors which perc lies in an evenly divided range. A HCY color
|
||||
is a sequence of 3 consecutive values in the range [0-1]. If `a` is negative or `b` is zero then the first
|
||||
HCY color (the first 3 HCY values passed to the function) is returned. If `a` is bigger than or equal to `b`, then the
|
||||
last 3 HCY values are returned.
|
||||
|
||||
* self - the global oUF object
|
||||
* a - value used as numerator to calculate the percentage (number)
|
||||
* b - value used as denominator to calculate the percentage (number)
|
||||
* ... - a list of HCY color values. At least 6 values should be passed (number [0-1])
|
||||
--]]
|
||||
function oUF:HCYColorGradient(...)
|
||||
local relperc, r1, g1, b1, r2, g2, b2 = colorsAndPercent(...)
|
||||
if(not relperc) then
|
||||
return r1, g1, b1
|
||||
end
|
||||
|
||||
local h1, c1, y1 = rgbToHCY(r1, g1, b1)
|
||||
local h2, c2, y2 = rgbToHCY(r2, g2, b2)
|
||||
local c = c1 + (c2 - c1) * relperc
|
||||
local y = y1 + (y2 - y1) * relperc
|
||||
|
||||
if(h1 and h2) then
|
||||
local dh = h2 - h1
|
||||
if(dh < -0.5) then
|
||||
dh = dh + 1
|
||||
elseif(dh > 0.5) then
|
||||
dh = dh - 1
|
||||
end
|
||||
|
||||
return hcyToRGB((h1 + dh * relperc) % 1, c, y)
|
||||
else
|
||||
return hcyToRGB(h1 or h2, c, y)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[ Colors: oUF:ColorGradient(a, b, ...) or frame:ColorGradient(a, b, ...)
|
||||
Used as a proxy to call the proper gradient function depending on the user's preference. If `oUF.useHCYColorGradient` is
|
||||
set to true, `:HCYColorGradient` will be called, else `:RGBColorGradient`.
|
||||
|
||||
* self - the global oUF object or a unit frame
|
||||
* a - value used as numerator to calculate the percentage (number)
|
||||
* b - value used as denominator to calculate the percentage (number)
|
||||
* ... - a list of color values. At least 6 values should be passed (number [0-1])
|
||||
--]]
|
||||
function oUF:ColorGradient(...)
|
||||
return (oUF.useHCYColorGradient and oUF.HCYColorGradient or oUF.RGBColorGradient)(self, ...)
|
||||
end
|
||||
|
||||
oUF.colors = colors
|
||||
oUF.useHCYColorGradient = false
|
||||
|
||||
frame_metatable.__index.colors = colors
|
||||
frame_metatable.__index.ColorGradient = oUF.ColorGradient
|
||||
@@ -0,0 +1,259 @@
|
||||
--[[
|
||||
# Element: Additional Power Bar
|
||||
|
||||
Handles the visibility and updating of a status bar that displays the player's additional power, such as Mana for druids.
|
||||
|
||||
## Widget
|
||||
|
||||
AdditionalPower - A `StatusBar` that is used to display the player's additional power.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.bg - A `Texture` used as a background. Inherits the widget's color.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
|
||||
|
||||
## Options
|
||||
|
||||
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
|
||||
|
||||
The following options are listed by priority. The first check that returns true decides the color of the bar.
|
||||
|
||||
.colorPower - Use `self.colors.power[token]` to color the bar based on the player's additional power type
|
||||
(boolean)
|
||||
.colorClass - Use `self.colors.class[class]` to color the bar based on unit class. `class` is defined by the
|
||||
second return of [UnitClass](http://wowprogramming.com/docs/api/UnitClass.html) (boolean)
|
||||
.colorSmooth - Use `self.colors.smooth` to color the bar with a smooth gradient based on the player's current
|
||||
additional power percentage (boolean)
|
||||
|
||||
## Sub-Widget Options
|
||||
|
||||
.multiplier - Used to tint the background based on the widget's R, G and B values. Defaults to 1 (number)[0-1]
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local AdditionalPower = CreateFrame('StatusBar', nil, self)
|
||||
AdditionalPower:SetSize(20, 20)
|
||||
AdditionalPower:SetPoint('TOP')
|
||||
AdditionalPower:SetPoint('LEFT')
|
||||
AdditionalPower:SetPoint('RIGHT')
|
||||
|
||||
-- Add a background
|
||||
local Background = AdditionalPower:CreateTexture(nil, 'BACKGROUND')
|
||||
Background:SetAllPoints(AdditionalPower)
|
||||
Background:SetTexture(1, 1, 1, .5)
|
||||
|
||||
-- Register it with oUF
|
||||
AdditionalPower.bg = Background
|
||||
self.AdditionalPower = AdditionalPower
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
-- ElvUI block
|
||||
local unpack = unpack
|
||||
local UnitIsPlayer = UnitIsPlayer
|
||||
local UnitClass = UnitClass
|
||||
local UnitPower = UnitPower
|
||||
local UnitPowerMax = UnitPowerMax
|
||||
local UnitHasVehicleUI = UnitHasVehicleUI
|
||||
local UnitPowerType = UnitPowerType
|
||||
-- end block
|
||||
|
||||
-- sourced from FrameXML/AlternatePowerBar.lua
|
||||
local ADDITIONAL_POWER_BAR_NAME = ADDITIONAL_POWER_BAR_NAME or 'MANA'
|
||||
local ADDITIONAL_POWER_BAR_INDEX = ADDITIONAL_POWER_BAR_INDEX or 0
|
||||
|
||||
local function UpdateColor(self, event, unit, powertype)
|
||||
if(not (unit and unit == 'player') and powertype == ADDITIONAL_POWER_BAR_NAME) then return end
|
||||
local element = self.AdditionalPower
|
||||
|
||||
local r, g, b, t
|
||||
if(element.colorPower) then
|
||||
t = self.colors.power[ADDITIONAL_POWER_BAR_INDEX]
|
||||
elseif(element.colorClass and UnitIsPlayer(unit)) then
|
||||
t = oUF.herocolor
|
||||
elseif(element.colorSmooth) then
|
||||
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
if(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = element.bg
|
||||
if(bg) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(unit, r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function ColorPath(self, ...)
|
||||
--[[ Override: AdditionalPower.UpdateColor(self, event, unit, ...)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.AdditionalPower.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function Update(self, event, unit, powertype)
|
||||
if(not (unit and unit == 'player') and powertype == ADDITIONAL_POWER_BAR_NAME) then return end
|
||||
|
||||
local element = self.AdditionalPower
|
||||
--[[ Callback: AdditionalPower:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the AdditionalPower element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local cur = UnitPower('player', ADDITIONAL_POWER_BAR_INDEX)
|
||||
local max = UnitPowerMax('player', ADDITIONAL_POWER_BAR_INDEX)
|
||||
|
||||
element:SetMinMaxValues(0, max)
|
||||
element:SetValue(cur)
|
||||
|
||||
element.cur = cur
|
||||
element.max = max
|
||||
|
||||
--[[ Callback: AdditionalPower:PostUpdate(unit, cur, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the AdditionalPower element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* cur - the current value of the player's additional power (number)
|
||||
* max - the maximum value of the player's additional power (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, cur, max, event) -- ElvUI adds event
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: AdditionalPower.Override(self, event, unit, ...)
|
||||
Used to completely override the element's update process.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.AdditionalPower.Override or Update) (self, ...)
|
||||
|
||||
ColorPath(self, ...)
|
||||
end
|
||||
|
||||
local function ElementEnable(self)
|
||||
local element = self.AdditionalPower
|
||||
|
||||
self:RegisterEvent('UNIT_MANA', Path)
|
||||
self:RegisterEvent('UNIT_MAXMANA', Path)
|
||||
|
||||
element:Show()
|
||||
|
||||
-- ElvUI block
|
||||
if element.PostUpdateVisibility then
|
||||
element:PostUpdateVisibility(true, not element.isEnabled)
|
||||
end
|
||||
|
||||
element.isEnabled = true
|
||||
-- end block
|
||||
|
||||
Path(self, 'ElementEnable', 'player', ADDITIONAL_POWER_BAR_NAME)
|
||||
end
|
||||
|
||||
local function ElementDisable(self)
|
||||
self:UnregisterEvent('UNIT_MAXMANA', Path)
|
||||
self:UnregisterEvent('UNIT_MANA', Path)
|
||||
|
||||
self.AdditionalPower:Hide()
|
||||
|
||||
-- ElvUI block
|
||||
local element = self.AdditionalPower
|
||||
if element.PostUpdateVisibility then
|
||||
element:PostUpdateVisibility(false, element.isEnabled)
|
||||
end
|
||||
|
||||
element.isEnabled = nil
|
||||
-- end block
|
||||
|
||||
Path(self, 'ElementDisable', 'player', ADDITIONAL_POWER_BAR_NAME)
|
||||
end
|
||||
|
||||
local function Visibility(self, event, unit)
|
||||
local element = self.AdditionalPower
|
||||
local shouldEnable
|
||||
|
||||
if(not UnitHasVehicleUI('player')) then
|
||||
if((UnitPowerType('player') ~= ADDITIONAL_POWER_BAR_INDEX) and (UnitPowerMax('player', ADDITIONAL_POWER_BAR_INDEX) ~= 0)) then
|
||||
shouldEnable = true
|
||||
end
|
||||
end
|
||||
|
||||
if(shouldEnable) then
|
||||
ElementEnable(self)
|
||||
else
|
||||
ElementDisable(self)
|
||||
end
|
||||
end
|
||||
|
||||
local function VisibilityPath(self, ...)
|
||||
--[[ Override: AdditionalPower.OverrideVisibility(self, event, unit)
|
||||
Used to completely override the element's visibility update process.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.AdditionalPower.OverrideVisibility or Visibility) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.AdditionalPower
|
||||
if(element and unit == 'player') then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
|
||||
|
||||
if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
|
||||
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.AdditionalPower
|
||||
if(element) then
|
||||
ElementDisable(self)
|
||||
|
||||
self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('AdditionalPower', VisibilityPath, Enable, Disable)
|
||||
@@ -0,0 +1,103 @@
|
||||
--[[
|
||||
# Element: Assistant Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the unit's raid assistant status.
|
||||
|
||||
## Widget
|
||||
|
||||
AssistantIndicator - Any UI widget.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local AssistantIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
AssistantIndicator:SetSize(16, 16)
|
||||
AssistantIndicator:SetPoint('TOP', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.AssistantIndicator = AssistantIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local UnitInRaid = UnitInRaid
|
||||
local UnitIsPartyLeader = UnitIsPartyLeader
|
||||
local UnitIsRaidOfficer = UnitIsRaidOfficer
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.AssistantIndicator
|
||||
|
||||
--[[ Callback: AssistantIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the AssistantIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local unit = self.unit
|
||||
local isAssistant = UnitInRaid(unit) and UnitIsRaidOfficer(unit) and not UnitIsPartyLeader(unit)
|
||||
if(isAssistant) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: AssistantIndicator:PostUpdate(isAssistant)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the AssistantIndicator element
|
||||
* isAssistant - indicates whether the unit is a raid assistant (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(isAssistant)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: AssistantIndicator.Override(self, event, ...)
|
||||
Used to completely override the element's update process.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event (string)
|
||||
--]]
|
||||
return (self.AssistantIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.AssistantIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('PARTY_MEMBERS_CHANGED', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\GroupFrame\UI-Group-AssistantIcon]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.AssistantIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('PARTY_MEMBERS_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('AssistantIndicator', Path, Enable, Disable)
|
||||
@@ -0,0 +1,611 @@
|
||||
--[[
|
||||
# Element: Auras
|
||||
|
||||
Handles creation and updating of aura icons.
|
||||
|
||||
## Widget
|
||||
|
||||
Auras - A Frame to hold `Button`s representing both buffs and debuffs.
|
||||
Buffs - A Frame to hold `Button`s representing buffs.
|
||||
Debuffs - A Frame to hold `Button`s representing debuffs.
|
||||
|
||||
## Notes
|
||||
|
||||
At least one of the above widgets must be present for the element to work.
|
||||
|
||||
## Options
|
||||
|
||||
.disableMouse - Disables mouse events (boolean)
|
||||
.disableCooldown - Disables the cooldown spiral (boolean)
|
||||
.size - Aura icon size. Defaults to 16 (number)
|
||||
.onlyShowPlayer - Shows only auras created by player/vehicle (boolean)
|
||||
.showStealableBuffs - Displays the stealable texture on buffs that can be stolen (boolean)
|
||||
.spacing - Spacing between each icon. Defaults to 0 (number)
|
||||
.['spacing-x'] - Horizontal spacing between each icon. Takes priority over `spacing` (number)
|
||||
.['spacing-y'] - Vertical spacing between each icon. Takes priority over `spacing` (number)
|
||||
.['growth-x'] - Horizontal growth direction. Defaults to 'RIGHT' (string)
|
||||
.['growth-y'] - Vertical growth direction. Defaults to 'UP' (string)
|
||||
.initialAnchor - Anchor point for the icons. Defaults to 'BOTTOMLEFT' (string)
|
||||
.filter - Custom filter list for auras to display. Defaults to 'HELPFUL' for buffs and 'HARMFUL' for
|
||||
debuffs (string)
|
||||
.tooltipAnchor - Anchor point for the tooltip. Defaults to 'ANCHOR_BOTTOMRIGHT', however, if a frame has anchoring
|
||||
restrictions it will be set to 'ANCHOR_CURSOR' (string)
|
||||
|
||||
## Options Auras
|
||||
|
||||
.numBuffs - The maximum number of buffs to display. Defaults to 32 (number)
|
||||
.numDebuffs - The maximum number of debuffs to display. Defaults to 40 (number)
|
||||
.numTotal - The maximum number of auras to display. Prioritizes buffs over debuffs. Defaults to the sum of
|
||||
.numBuffs and .numDebuffs (number)
|
||||
.gap - Controls the creation of an invisible icon between buffs and debuffs. Defaults to false (boolean)
|
||||
.buffFilter - Custom filter list for buffs to display. Takes priority over `filter` (string)
|
||||
.debuffFilter - Custom filter list for debuffs to display. Takes priority over `filter` (string)
|
||||
|
||||
## Options Buffs
|
||||
|
||||
.num - Number of buffs to display. Defaults to 32 (number)
|
||||
|
||||
## Options Debuffs
|
||||
|
||||
.num - Number of debuffs to display. Defaults to 40 (number)
|
||||
|
||||
## Attributes
|
||||
|
||||
button.caster - the unit who cast the aura (string)
|
||||
button.filter - the filter list used to determine the visibility of the aura (string)
|
||||
button.isDebuff - indicates if the button holds a debuff (boolean)
|
||||
button.isPlayer - indicates if the aura caster is the player or their vehicle (boolean)
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local Buffs = CreateFrame('Frame', nil, self)
|
||||
Buffs:SetPoint('RIGHT', self, 'LEFT')
|
||||
Buffs:SetSize(16 * 2, 16 * 16)
|
||||
|
||||
-- Register with oUF
|
||||
self.Buffs = Buffs
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local VISIBLE = 1
|
||||
local HIDDEN = 0
|
||||
|
||||
-- ElvUI changed block
|
||||
local CREATED = 2
|
||||
local pcall = pcall
|
||||
local tinsert = tinsert
|
||||
local CreateFrame = CreateFrame
|
||||
local GetSpellInfo = GetSpellInfo
|
||||
local UnitAura = UnitAura
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local floor, min = math.floor, math.min
|
||||
-- GLOBALS: GameTooltip
|
||||
-- end block
|
||||
|
||||
local function UpdateTooltip(self)
|
||||
GameTooltip:SetUnitAura(self:GetParent().__owner.unit, self:GetID(), self.filter)
|
||||
end
|
||||
|
||||
local function onEnter(self)
|
||||
if(not self:IsVisible()) then return end
|
||||
|
||||
GameTooltip:SetOwner(self, self:GetParent().tooltipAnchor)
|
||||
self:UpdateTooltip()
|
||||
end
|
||||
|
||||
local function onLeave()
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
local function createAuraIcon(element, index)
|
||||
local button = CreateFrame('Button', '$parentButton' .. index, element)
|
||||
button:RegisterForClicks('RightButtonUp')
|
||||
|
||||
local cd = CreateFrame('Cooldown', '$parentCooldown', button, 'CooldownFrameTemplate')
|
||||
cd:SetFrameLevel(button:GetFrameLevel() + 1)
|
||||
cd:SetAllPoints()
|
||||
|
||||
local icon = button:CreateTexture(nil, 'BORDER')
|
||||
icon:SetAllPoints()
|
||||
|
||||
local countFrame = CreateFrame('Frame', '$parentCount', button)
|
||||
countFrame:SetAllPoints(button)
|
||||
countFrame:SetFrameLevel(cd:GetFrameLevel() + 1)
|
||||
|
||||
local count = countFrame:CreateFontString(nil, 'OVERLAY', 'NumberFontNormal')
|
||||
count:SetPoint('BOTTOMRIGHT', countFrame, 'BOTTOMRIGHT', -1, 0)
|
||||
|
||||
local overlay = button:CreateTexture(nil, 'OVERLAY')
|
||||
overlay:SetTexture([[Interface\Buttons\UI-Debuff-Overlays]])
|
||||
overlay:SetAllPoints()
|
||||
overlay:SetTexCoord(.296875, .5703125, 0, .515625)
|
||||
button.overlay = overlay
|
||||
|
||||
local stealable = button:CreateTexture(nil, 'OVERLAY')
|
||||
stealable:SetTexture([[Interface\TargetingFrame\UI-TargetingFrame-Stealable]])
|
||||
stealable:SetPoint('TOPLEFT', -3, 3)
|
||||
stealable:SetPoint('BOTTOMRIGHT', 3, -3)
|
||||
stealable:SetBlendMode('ADD')
|
||||
button.stealable = stealable
|
||||
|
||||
button.UpdateTooltip = UpdateTooltip
|
||||
button:SetScript('OnEnter', onEnter)
|
||||
button:SetScript('OnLeave', onLeave)
|
||||
|
||||
button.icon = icon
|
||||
button.count = count
|
||||
button.cd = cd
|
||||
|
||||
--[[ Callback: Auras:PostCreateIcon(button)
|
||||
Called after a new aura button has been created.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* button - the newly created aura button (Button)
|
||||
--]]
|
||||
if(element.PostCreateIcon) then element:PostCreateIcon(button) end
|
||||
|
||||
return button
|
||||
end
|
||||
|
||||
local function customFilter(element, unit, button, name)
|
||||
if((element.onlyShowPlayer and button.isPlayer) or (not element.onlyShowPlayer and name)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function updateIcon(element, unit, index, offset, filter, isDebuff, visible)
|
||||
local name, rank, texture, count, debuffType, duration, expiration, caster, isStealable, shouldConsolidate, spellID = UnitAura(unit, index, filter)
|
||||
|
||||
-- count may be nil sometimes
|
||||
count = count or 0
|
||||
|
||||
-- ElvUI block
|
||||
if element.forceShow or element.forceCreate then
|
||||
spellID = 47540
|
||||
name, rank, texture = GetSpellInfo(spellID)
|
||||
if element.forceShow then
|
||||
count, debuffType, duration, expiration, caster, isStealable, shouldConsolidate = 5, 'Magic', 0, 60, 'player', nil, nil
|
||||
end
|
||||
end
|
||||
-- end Block
|
||||
|
||||
if(name) then
|
||||
local position = visible + offset + 1
|
||||
local button = element[position]
|
||||
if(not button) then
|
||||
--[[ Override: Auras:CreateIcon(position)
|
||||
Used to create the aura button at a given position.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* position - the position at which the aura button is to be created (number)
|
||||
|
||||
## Returns
|
||||
|
||||
* button - the button used to represent the aura (Button)
|
||||
--]]
|
||||
button = (element.CreateIcon or createAuraIcon) (element, position)
|
||||
|
||||
tinsert(element, button)
|
||||
element.createdIcons = element.createdIcons + 1
|
||||
end
|
||||
|
||||
button.caster = caster
|
||||
button.filter = filter
|
||||
button.isDebuff = isDebuff
|
||||
button.isPlayer = caster == 'player' or caster == 'vehicle'
|
||||
|
||||
--[[ Override: Auras:CustomFilter(unit, button, ...)
|
||||
Defines a custom filter that controls if the aura button should be shown.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit on which the aura is cast (string)
|
||||
* button - the button displaying the aura (Button)
|
||||
* ... - the return values from [UnitAura](http://wowprogramming.com/docs/api/UnitAura.html)
|
||||
|
||||
## Returns
|
||||
|
||||
* show - indicates whether the aura button should be shown (boolean)
|
||||
--]]
|
||||
|
||||
-- ElvUI changed block
|
||||
local show = not element.forceCreate
|
||||
if not (element.forceShow or element.forceCreate) then
|
||||
show = (element.CustomFilter or customFilter) (element, unit, button, name, rank, texture, count, debuffType, duration, expiration, caster, isStealable, shouldConsolidate, spellID)
|
||||
end
|
||||
-- end block
|
||||
|
||||
if(show) then
|
||||
-- We might want to consider delaying the creation of an actual cooldown
|
||||
-- object to this point, but I think that will just make things needlessly
|
||||
-- complicated.
|
||||
if(button.cd and not element.disableCooldown) then
|
||||
if(duration and duration > 0) then
|
||||
button.cd:SetCooldown(expiration - duration, duration)
|
||||
button.cd:Show()
|
||||
else
|
||||
button.cd:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(button.overlay) then
|
||||
if((isDebuff and element.showDebuffType) or (not isDebuff and element.showBuffType) or element.showType) then
|
||||
local color = element.__owner.colors.debuff[debuffType] or element.__owner.colors.debuff.none
|
||||
|
||||
button.overlay:SetVertexColor(color[1], color[2], color[3])
|
||||
button.overlay:Show()
|
||||
else
|
||||
button.overlay:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(button.stealable) then
|
||||
if(not isDebuff and isStealable and element.showStealableBuffs and not UnitIsUnit('player', unit)) then
|
||||
button.stealable:Show()
|
||||
else
|
||||
button.stealable:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(button.icon) then button.icon:SetTexture(texture) end
|
||||
if(button.count) then button.count:SetText(count > 1 and count) end
|
||||
|
||||
local size = element.size or 16
|
||||
button:SetSize(size, size)
|
||||
|
||||
button:EnableMouse(not element.disableMouse)
|
||||
button:SetID(index)
|
||||
button:Show()
|
||||
|
||||
--[[ Callback: Auras:PostUpdateIcon(unit, button, index, position)
|
||||
Called after the aura button has been updated.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit on which the aura is cast (string)
|
||||
* button - the updated aura button (Button)
|
||||
* index - the index of the aura (number)
|
||||
* position - the actual position of the aura button (number)
|
||||
* duration - the aura duration in seconds (number?)
|
||||
* expiration - the point in time when the aura will expire. Comparable to GetTime() (number)
|
||||
* debuffType - the debuff type of the aura (string?)['Curse', 'Disease', 'Magic', 'Poison']
|
||||
* isStealable - whether the aura can be stolen or purged (boolean)
|
||||
--]]
|
||||
if(element.PostUpdateIcon) then
|
||||
element:PostUpdateIcon(unit, button, index, position, duration, expiration, debuffType, isStealable)
|
||||
end
|
||||
|
||||
return VISIBLE
|
||||
-- ElvUI changed block
|
||||
elseif element.forceCreate then
|
||||
local size = element.size or 16
|
||||
button:SetSize(size, size)
|
||||
button:Hide()
|
||||
|
||||
if element.PostUpdateIcon then
|
||||
element:PostUpdateIcon(unit, button, index, position, duration, expiration, debuffType, isStealable)
|
||||
end
|
||||
|
||||
return CREATED
|
||||
-- end block
|
||||
else
|
||||
return HIDDEN
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function SetPosition(element, from, to)
|
||||
local sizex = (element.size or 16) + (element['spacing-x'] or element.spacing or 0)
|
||||
local sizey = (element.size or 16) + (element['spacing-y'] or element.spacing or 0)
|
||||
local anchor = element.initialAnchor or 'BOTTOMLEFT'
|
||||
local growthx = (element['growth-x'] == 'LEFT' and -1) or 1
|
||||
local growthy = (element['growth-y'] == 'DOWN' and -1) or 1
|
||||
local cols = floor(element:GetWidth() / sizex + 0.5)
|
||||
|
||||
for i = from, to do
|
||||
local button = element[i]
|
||||
|
||||
-- Bail out if the to range is out of scope.
|
||||
if(not button) then break end
|
||||
local col = (i - 1) % cols
|
||||
local row = floor((i - 1) / cols)
|
||||
|
||||
button:ClearAllPoints()
|
||||
button:SetPoint(anchor, element, anchor, col * sizex * growthx, row * sizey * growthy)
|
||||
end
|
||||
end
|
||||
|
||||
local function filterIcons(element, unit, filter, limit, isDebuff, offset, dontHide)
|
||||
if(not offset) then offset = 0 end
|
||||
local index = 1
|
||||
local visible = 0
|
||||
local hidden = 0
|
||||
-- ElvUI changed block
|
||||
local created = 0
|
||||
-- end block
|
||||
while(visible < limit) do
|
||||
local result = updateIcon(element, unit, index, offset, filter, isDebuff, visible)
|
||||
if(not result) then
|
||||
break
|
||||
elseif(result == VISIBLE) then
|
||||
visible = visible + 1
|
||||
elseif(result == HIDDEN) then
|
||||
hidden = hidden + 1
|
||||
-- ElvUI changed block
|
||||
elseif result == CREATED then
|
||||
visible = visible + 1
|
||||
created = created + 1
|
||||
-- end block
|
||||
end
|
||||
|
||||
index = index + 1
|
||||
end
|
||||
|
||||
-- ElvUI changed block
|
||||
visible = visible - created
|
||||
-- end block
|
||||
|
||||
if(not dontHide) then
|
||||
for i = visible + offset + 1, #element do
|
||||
element[i]:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
return visible, hidden
|
||||
end
|
||||
|
||||
local function UpdateAuras(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local auras = self.Auras
|
||||
if(auras) then
|
||||
--[[ Callback: Auras:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(auras.PreUpdate) then auras:PreUpdate(unit) end
|
||||
|
||||
local numBuffs = auras.numBuffs or 32
|
||||
local numDebuffs = auras.numDebuffs or 40
|
||||
local max = auras.numTotal or numBuffs + numDebuffs
|
||||
|
||||
local visibleBuffs = filterIcons(auras, unit, auras.buffFilter or auras.filter or 'HELPFUL', min(numBuffs, max), nil, 0, true)
|
||||
|
||||
local hasGap
|
||||
if(visibleBuffs ~= 0 and auras.gap) then
|
||||
hasGap = true
|
||||
visibleBuffs = visibleBuffs + 1
|
||||
|
||||
local button = auras[visibleBuffs]
|
||||
if(not button) then
|
||||
button = (auras.CreateIcon or createAuraIcon) (auras, visibleBuffs)
|
||||
tinsert(auras, button)
|
||||
auras.createdIcons = auras.createdIcons + 1
|
||||
end
|
||||
|
||||
-- Prevent the button from displaying anything.
|
||||
if(button.cd) then button.cd:Hide() end
|
||||
if(button.icon) then button.icon:SetTexture() end
|
||||
if(button.overlay) then button.overlay:Hide() end
|
||||
if(button.stealable) then button.stealable:Hide() end
|
||||
if(button.count) then button.count:SetText() end
|
||||
|
||||
button:EnableMouse(false)
|
||||
button:Show()
|
||||
|
||||
--[[ Callback: Auras:PostUpdateGapIcon(unit, gapButton, visibleBuffs)
|
||||
Called after an invisible aura button has been created. Only used by Auras when the `gap` option is enabled.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit that has the invisible aura button (string)
|
||||
* gapButton - the invisible aura button (Button)
|
||||
* visibleBuffs - the number of currently visible aura buttons (number)
|
||||
--]]
|
||||
if(auras.PostUpdateGapIcon) then
|
||||
auras:PostUpdateGapIcon(unit, button, visibleBuffs)
|
||||
end
|
||||
end
|
||||
|
||||
local visibleDebuffs = filterIcons(auras, unit, auras.debuffFilter or auras.filter or 'HARMFUL', min(numDebuffs, max - visibleBuffs), true, visibleBuffs)
|
||||
auras.visibleDebuffs = visibleDebuffs
|
||||
|
||||
if(hasGap and visibleDebuffs == 0) then
|
||||
auras[visibleBuffs]:Hide()
|
||||
visibleBuffs = visibleBuffs - 1
|
||||
end
|
||||
|
||||
auras.visibleBuffs = visibleBuffs
|
||||
auras.visibleAuras = auras.visibleBuffs + auras.visibleDebuffs
|
||||
|
||||
local fromRange, toRange
|
||||
--[[ Callback: Auras:PreSetPosition(max)
|
||||
Called before the aura buttons have been (re-)anchored.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* max - the maximum possible number of aura buttons (number)
|
||||
|
||||
## Returns
|
||||
|
||||
* from - the offset of the first aura button to be (re-)anchored (number)
|
||||
* to - the offset of the last aura button to be (re-)anchored (number)
|
||||
--]]
|
||||
if(auras.PreSetPosition) then
|
||||
fromRange, toRange = auras:PreSetPosition(max)
|
||||
end
|
||||
|
||||
if(fromRange or auras.createdIcons > auras.anchoredIcons) then
|
||||
--[[ Override: Auras:SetPosition(from, to)
|
||||
Used to (re-)anchor the aura buttons.
|
||||
Called when new aura buttons have been created or if :PreSetPosition is defined.
|
||||
|
||||
* self - the widget that holds the aura buttons
|
||||
* from - the offset of the first aura button to be (re-)anchored (number)
|
||||
* to - the offset of the last aura button to be (re-)anchored (number)
|
||||
--]]
|
||||
(auras.SetPosition or SetPosition) (auras, fromRange or auras.anchoredIcons + 1, toRange or auras.createdIcons)
|
||||
auras.anchoredIcons = auras.createdIcons
|
||||
end
|
||||
|
||||
--[[ Callback: Auras:PostUpdate(unit)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(auras.PostUpdate) then auras:PostUpdate(unit) end
|
||||
end
|
||||
|
||||
local buffs = self.Buffs
|
||||
if(buffs) then
|
||||
if(buffs.PreUpdate) then buffs:PreUpdate(unit) end
|
||||
|
||||
local numBuffs = buffs.num or 32
|
||||
local visibleBuffs = filterIcons(buffs, unit, buffs.filter or 'HELPFUL', numBuffs)
|
||||
buffs.visibleBuffs = visibleBuffs
|
||||
|
||||
local fromRange, toRange
|
||||
if(buffs.PreSetPosition) then
|
||||
fromRange, toRange = buffs:PreSetPosition(numBuffs)
|
||||
end
|
||||
|
||||
if(fromRange or buffs.createdIcons > buffs.anchoredIcons) then
|
||||
(buffs.SetPosition or SetPosition) (buffs, fromRange or buffs.anchoredIcons + 1, toRange or buffs.createdIcons)
|
||||
buffs.anchoredIcons = buffs.createdIcons
|
||||
end
|
||||
|
||||
if(buffs.PostUpdate) then buffs:PostUpdate(unit) end
|
||||
end
|
||||
|
||||
local debuffs = self.Debuffs
|
||||
if(debuffs) then
|
||||
if(debuffs.PreUpdate) then debuffs:PreUpdate(unit) end
|
||||
|
||||
local numDebuffs = debuffs.num or 40
|
||||
local visibleDebuffs = filterIcons(debuffs, unit, debuffs.filter or 'HARMFUL', numDebuffs, true)
|
||||
debuffs.visibleDebuffs = visibleDebuffs
|
||||
|
||||
local fromRange, toRange
|
||||
if(debuffs.PreSetPosition) then
|
||||
fromRange, toRange = debuffs:PreSetPosition(numDebuffs)
|
||||
end
|
||||
|
||||
if(fromRange or debuffs.createdIcons > debuffs.anchoredIcons) then
|
||||
(debuffs.SetPosition or SetPosition) (debuffs, fromRange or debuffs.anchoredIcons + 1, toRange or debuffs.createdIcons)
|
||||
debuffs.anchoredIcons = debuffs.createdIcons
|
||||
end
|
||||
|
||||
if(debuffs.PostUpdate) then debuffs:PostUpdate(unit) end
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
UpdateAuras(self, event, unit)
|
||||
|
||||
-- Assume no event means someone wants to re-anchor things. This is usually
|
||||
-- done by UpdateAllElements and :ForceUpdate.
|
||||
if(event == 'ForceUpdate' or not event) then
|
||||
local buffs = self.Buffs
|
||||
if(buffs) then
|
||||
(buffs.SetPosition or SetPosition) (buffs, 1, buffs.createdIcons)
|
||||
end
|
||||
|
||||
local debuffs = self.Debuffs
|
||||
if(debuffs) then
|
||||
(debuffs.SetPosition or SetPosition) (debuffs, 1, debuffs.createdIcons)
|
||||
end
|
||||
|
||||
local auras = self.Auras
|
||||
if(auras) then
|
||||
(auras.SetPosition or SetPosition) (auras, 1, auras.createdIcons)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Update(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
if(self.Buffs or self.Debuffs or self.Auras) then
|
||||
self:RegisterEvent('UNIT_AURA', UpdateAuras)
|
||||
|
||||
local buffs = self.Buffs
|
||||
if(buffs) then
|
||||
buffs.__owner = self
|
||||
buffs.ForceUpdate = ForceUpdate
|
||||
|
||||
buffs.createdIcons = buffs.createdIcons or 0
|
||||
buffs.anchoredIcons = 0
|
||||
|
||||
-- Avoid parenting GameTooltip to frames with anchoring restrictions,
|
||||
-- otherwise it'll inherit said restrictions which will cause issues
|
||||
-- with its further positioning, clamping, etc
|
||||
if(not pcall(self.GetCenter, self)) then
|
||||
buffs.tooltipAnchor = 'ANCHOR_CURSOR'
|
||||
else
|
||||
buffs.tooltipAnchor = buffs.tooltipAnchor or 'ANCHOR_BOTTOMRIGHT'
|
||||
end
|
||||
|
||||
buffs:Show()
|
||||
end
|
||||
|
||||
local debuffs = self.Debuffs
|
||||
if(debuffs) then
|
||||
debuffs.__owner = self
|
||||
debuffs.ForceUpdate = ForceUpdate
|
||||
|
||||
debuffs.createdIcons = debuffs.createdIcons or 0
|
||||
debuffs.anchoredIcons = 0
|
||||
|
||||
-- Avoid parenting GameTooltip to frames with anchoring restrictions,
|
||||
-- otherwise it'll inherit said restrictions which will cause issues
|
||||
-- with its further positioning, clamping, etc
|
||||
if(not pcall(self.GetCenter, self)) then
|
||||
debuffs.tooltipAnchor = 'ANCHOR_CURSOR'
|
||||
else
|
||||
debuffs.tooltipAnchor = debuffs.tooltipAnchor or 'ANCHOR_BOTTOMRIGHT'
|
||||
end
|
||||
|
||||
debuffs:Show()
|
||||
end
|
||||
|
||||
local auras = self.Auras
|
||||
if(auras) then
|
||||
auras.__owner = self
|
||||
auras.ForceUpdate = ForceUpdate
|
||||
|
||||
auras.createdIcons = auras.createdIcons or 0
|
||||
auras.anchoredIcons = 0
|
||||
|
||||
-- Avoid parenting GameTooltip to frames with anchoring restrictions,
|
||||
-- otherwise it'll inherit said restrictions which will cause issues
|
||||
-- with its further positioning, clamping, etc
|
||||
if(not pcall(self.GetCenter, self)) then
|
||||
auras.tooltipAnchor = 'ANCHOR_CURSOR'
|
||||
else
|
||||
auras.tooltipAnchor = auras.tooltipAnchor or 'ANCHOR_BOTTOMRIGHT'
|
||||
end
|
||||
|
||||
auras:Show()
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
if(self.Buffs or self.Debuffs or self.Auras) then
|
||||
self:UnregisterEvent('UNIT_AURA', UpdateAuras)
|
||||
|
||||
if(self.Buffs) then self.Buffs:Hide() end
|
||||
if(self.Debuffs) then self.Debuffs:Hide() end
|
||||
if(self.Auras) then self.Auras:Hide() end
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Auras', Update, Enable, Disable)
|
||||
@@ -0,0 +1,544 @@
|
||||
--[[
|
||||
# Element: Castbar
|
||||
|
||||
Handles the visibility and updating of spell castbars.
|
||||
|
||||
## Widget
|
||||
|
||||
Castbar - A `StatusBar` to represent spell cast/channel progress.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.Icon - A `Texture` to represent spell icon.
|
||||
.SafeZone - A `Texture` to represent latency.
|
||||
.Shield - A `Texture` to represent if it's possible to interrupt or spell steal.
|
||||
.Spark - A `Texture` to represent the castbar's edge.
|
||||
.Text - A `FontString` to represent spell name.
|
||||
.Time - A `FontString` to represent spell duration.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied to the StatusBar and Texture widgets if they don't have a texture or a color set.
|
||||
|
||||
## Options
|
||||
|
||||
.timeToHold - Indicates for how many seconds the castbar should be visible after a _FAILED or _INTERRUPTED
|
||||
event. Defaults to 0 (number)
|
||||
.hideTradeSkills - Makes the element ignore casts related to crafting professions (boolean)
|
||||
|
||||
## Attributes
|
||||
|
||||
.castID - A globally unique identifier of the currently cast spell (string?)
|
||||
.casting - Indicates whether the current spell is an ordinary cast (boolean)
|
||||
.channeling - Indicates whether the current spell is a channeled cast (boolean)
|
||||
.notInterruptible - Indicates whether the current spell is interruptible (boolean)
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local Castbar = CreateFrame('StatusBar', nil, self)
|
||||
Castbar:SetSize(20, 20)
|
||||
Castbar:SetPoint('TOP')
|
||||
Castbar:SetPoint('LEFT')
|
||||
Castbar:SetPoint('RIGHT')
|
||||
|
||||
-- Add a background
|
||||
local Background = Castbar:CreateTexture(nil, 'BACKGROUND')
|
||||
Background:SetAllPoints(Castbar)
|
||||
Background:SetTexture(1, 1, 1, .5)
|
||||
|
||||
-- Add a spark
|
||||
local Spark = Castbar:CreateTexture(nil, 'OVERLAY')
|
||||
Spark:SetSize(20, 20)
|
||||
Spark:SetBlendMode('ADD')
|
||||
Spark:SetPoint('CENTER', Castbar:GetStatusBarTexture(), 'RIGHT', 0, 0)
|
||||
|
||||
-- Add a timer
|
||||
local Time = Castbar:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
|
||||
Time:SetPoint('RIGHT', Castbar)
|
||||
|
||||
-- Add spell text
|
||||
local Text = Castbar:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
|
||||
Text:SetPoint('LEFT', Castbar)
|
||||
|
||||
-- Add spell icon
|
||||
local Icon = Castbar:CreateTexture(nil, 'OVERLAY')
|
||||
Icon:SetSize(20, 20)
|
||||
Icon:SetPoint('TOPLEFT', Castbar, 'TOPLEFT')
|
||||
|
||||
-- Add Shield
|
||||
local Shield = Castbar:CreateTexture(nil, 'OVERLAY')
|
||||
Shield:SetSize(20, 20)
|
||||
Shield:SetPoint('CENTER', Castbar)
|
||||
|
||||
-- Add safezone
|
||||
local SafeZone = Castbar:CreateTexture(nil, 'OVERLAY')
|
||||
|
||||
-- Register it with oUF
|
||||
Castbar.bg = Background
|
||||
Castbar.Spark = Spark
|
||||
Castbar.Time = Time
|
||||
Castbar.Text = Text
|
||||
Castbar.Icon = Icon
|
||||
Castbar.Shield = Shield
|
||||
Castbar.SafeZone = SafeZone
|
||||
self.Castbar = Castbar
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local select = select
|
||||
local GetNetStats = GetNetStats
|
||||
local GetTime = GetTime
|
||||
local UnitCastingInfo = UnitCastingInfo
|
||||
local UnitChannelInfo = UnitChannelInfo
|
||||
local tradeskillCurrent, tradeskillTotal, mergeTradeskill = 0, 0, false -- ElvUI
|
||||
|
||||
local DEFAULT_ICON = [[Interface\ICONS\INV_Misc_QuestionMark]]
|
||||
|
||||
local function resetAttributes(self)
|
||||
self.castID = nil
|
||||
self.casting = nil
|
||||
self.channeling = nil
|
||||
self.notInterruptible = nil
|
||||
self.spellName = nil -- ElvUI
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
local UNIT_SPELLCAST_SENT = function (self, event, unit, _, _, target)
|
||||
local castbar = self.Castbar
|
||||
castbar.curTarget = (target and target ~= "") and target or nil
|
||||
end
|
||||
-- end block
|
||||
|
||||
local function CastStart(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.Castbar
|
||||
local name, _, _, texture, startTime, endTime, isTradeSkill, castID, notInterruptible = UnitCastingInfo(unit)
|
||||
event = 'UNIT_SPELLCAST_START'
|
||||
if(not name) then
|
||||
name, _, _, texture, startTime, endTime, isTradeSkill, notInterruptible = UnitChannelInfo(unit)
|
||||
event = 'UNIT_SPELLCAST_CHANNEL_START'
|
||||
end
|
||||
|
||||
if(not name or (isTradeSkill and element.hideTradeSkills)) then
|
||||
resetAttributes(element)
|
||||
element:Hide()
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
endTime = endTime / 1000
|
||||
startTime = startTime / 1000
|
||||
|
||||
element.max = endTime - startTime
|
||||
element.startTime = startTime
|
||||
element.delay = 0
|
||||
element.casting = event == 'UNIT_SPELLCAST_START'
|
||||
element.channeling = event == 'UNIT_SPELLCAST_CHANNEL_START'
|
||||
element.notInterruptible = notInterruptible
|
||||
element.holdTime = 0
|
||||
element.castID = castID
|
||||
element.spellName = name -- ElvUI
|
||||
|
||||
if(element.casting) then
|
||||
element.duration = GetTime() - startTime
|
||||
else
|
||||
element.duration = endTime - GetTime()
|
||||
end
|
||||
|
||||
if(mergeTradeskill and isTradeSkill and self.unit == 'player') then
|
||||
element.duration = element.duration + (element.max * tradeskillCurrent)
|
||||
element.max = element.max * tradeskillTotal
|
||||
element.holdTime = 1
|
||||
element.tradeSkillCastId = castID
|
||||
|
||||
if(unit == "player") then
|
||||
tradeskillCurrent = tradeskillCurrent + 1
|
||||
end
|
||||
end
|
||||
|
||||
element:SetMinMaxValues(0, element.max)
|
||||
element:SetValue(element.duration)
|
||||
|
||||
if(element.Icon) then element.Icon:SetTexture(texture or DEFAULT_ICON) end
|
||||
if(element.Shield) then element.Shield:SetShown(notInterruptible) end
|
||||
if(element.Spark) then element.Spark:Show() end
|
||||
if(element.Text) then element.Text:SetText(name) end
|
||||
if(element.Time) then element.Time:SetText() end
|
||||
|
||||
local safeZone = element.SafeZone
|
||||
if(safeZone) then
|
||||
local isHoriz = element:GetOrientation() == 'HORIZONTAL'
|
||||
|
||||
safeZone:ClearAllPoints()
|
||||
safeZone:SetPoint(isHoriz and 'TOP' or 'LEFT')
|
||||
safeZone:SetPoint(isHoriz and 'BOTTOM' or 'RIGHT')
|
||||
|
||||
if(element.casting) then
|
||||
safeZone:SetPoint(isHoriz and 'RIGHT' or 'TOP')
|
||||
else
|
||||
safeZone:SetPoint(isHoriz and 'LEFT' or 'BOTTOM')
|
||||
end
|
||||
|
||||
local ratio = (select(3, GetNetStats()) / 1000) / element.max
|
||||
if(ratio > 1) then
|
||||
ratio = 1
|
||||
end
|
||||
|
||||
safeZone[isHoriz and 'SetWidth' or 'SetHeight'](safeZone, element[isHoriz and 'GetWidth' or 'GetHeight'](element) * ratio)
|
||||
end
|
||||
|
||||
--[[ Callback: Castbar:PostCastStart(unit)
|
||||
Called after the element has been updated upon a spell cast start.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostCastStart) then
|
||||
element:PostCastStart(unit)
|
||||
end
|
||||
|
||||
element:Show()
|
||||
end
|
||||
|
||||
local function CastUpdate(self, event, unit, _, _, castID)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.Castbar
|
||||
if(not element:IsShown() or element.castID and element.castID ~= castID) then
|
||||
return
|
||||
end
|
||||
|
||||
local name, startTime, endTime, _
|
||||
if(event == 'UNIT_SPELLCAST_DELAYED') then
|
||||
name, _, _, _, startTime, endTime = UnitCastingInfo(unit)
|
||||
else
|
||||
name, _, _, _, startTime, endTime = UnitChannelInfo(unit)
|
||||
end
|
||||
|
||||
if(not name) then return end
|
||||
|
||||
endTime = endTime / 1000
|
||||
startTime = startTime / 1000
|
||||
|
||||
local delta
|
||||
if(element.casting) then
|
||||
delta = startTime - element.startTime
|
||||
|
||||
element.duration = GetTime() - startTime
|
||||
else
|
||||
delta = element.startTime - startTime
|
||||
|
||||
element.duration = endTime - GetTime()
|
||||
end
|
||||
|
||||
if(delta < 0) then
|
||||
delta = 0
|
||||
end
|
||||
|
||||
element.max = endTime - startTime
|
||||
element.startTime = startTime
|
||||
element.delay = element.delay + delta
|
||||
|
||||
element:SetMinMaxValues(0, element.max)
|
||||
element:SetValue(element.duration)
|
||||
|
||||
--[[ Callback: Castbar:PostCastUpdate(unit)
|
||||
Called after the element has been updated when a spell cast has been updated.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit that the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostCastUpdate) then
|
||||
return element:PostCastUpdate(unit)
|
||||
end
|
||||
end
|
||||
|
||||
local function CastStop(self, event, unit, _, _, castID)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.Castbar
|
||||
if(not element:IsShown() or element.castID and element.castID ~= castID) then
|
||||
return
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
if(mergeTradeskill and self.unit == 'player') then
|
||||
if(tradeskillCurrent == tradeskillTotal) then
|
||||
mergeTradeskill = false
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
resetAttributes(element)
|
||||
|
||||
--[[ Callback: Castbar:PostCastStop(unit)
|
||||
Called after the element has been updated when a spell cast has stopped.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostCastStop) then
|
||||
return element:PostCastStop(unit)
|
||||
end
|
||||
end
|
||||
|
||||
local function CastFail(self, event, unit, _, _, castID)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.Castbar
|
||||
if(not element:IsShown() or element.castID ~= castID) then
|
||||
return
|
||||
end
|
||||
|
||||
if(element.Text) then
|
||||
element.Text:SetText(event == 'UNIT_SPELLCAST_FAILED' and FAILED or INTERRUPTED)
|
||||
end
|
||||
|
||||
if(element.Spark) then element.Spark:Hide() end
|
||||
|
||||
element.holdTime = element.timeToHold or 0
|
||||
|
||||
-- ElvUI block
|
||||
if(mergeTradeskill and self.unit == 'player') then
|
||||
mergeTradeskill = false
|
||||
element.tradeSkillCastId = nil
|
||||
end
|
||||
-- end block
|
||||
|
||||
resetAttributes(element)
|
||||
element:SetValue(element.max)
|
||||
|
||||
--[[ Callback: Castbar:PostCastFail(unit)
|
||||
Called after the element has been updated upon a failed spell cast.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostCastFail) then
|
||||
return element:PostCastFail(unit)
|
||||
end
|
||||
end
|
||||
|
||||
local function CastInterruptible(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.Castbar
|
||||
if(not element:IsShown()) then return end
|
||||
|
||||
element.notInterruptible = event == 'UNIT_SPELLCAST_NOT_INTERRUPTIBLE'
|
||||
|
||||
if(element.Shield) then element.Shield:SetShown(element.notInterruptible) end
|
||||
|
||||
--[[ Callback: Castbar:PostCastInterruptible(unit)
|
||||
Called after the element has been updated when a spell cast has become interruptible or uninterruptible.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostCastInterruptible) then
|
||||
return element:PostCastInterruptible(unit)
|
||||
end
|
||||
end
|
||||
|
||||
local function onUpdate(self, elapsed)
|
||||
if(self.casting or self.channeling) then
|
||||
local isCasting = self.casting
|
||||
if(isCasting) then
|
||||
self.duration = self.duration + elapsed
|
||||
if(self.duration >= self.max) then
|
||||
|
||||
resetAttributes(self)
|
||||
self:Hide()
|
||||
|
||||
if(self.PostCastStop) then
|
||||
self:PostCastStop(self.__owner.unit)
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
else
|
||||
self.duration = self.duration - elapsed
|
||||
if(self.duration <= 0) then
|
||||
|
||||
resetAttributes(self)
|
||||
self:Hide()
|
||||
|
||||
if(self.PostCastStop) then
|
||||
self:PostCastStop(self.__owner.unit)
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if(self.Time) then
|
||||
if(self.delay ~= 0) then
|
||||
if(self.CustomDelayText) then
|
||||
self:CustomDelayText(self.duration)
|
||||
else
|
||||
self.Time:SetFormattedText('%.1f|cffff0000%s%.2f|r', self.duration, isCasting and '+' or '-', self.delay)
|
||||
end
|
||||
else
|
||||
if(self.CustomTimeText) then
|
||||
self:CustomTimeText(self.duration)
|
||||
else
|
||||
self.Time:SetFormattedText('%.1f', self.duration)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self:SetValue(self.duration)
|
||||
elseif(self.holdTime > 0) then
|
||||
self.holdTime = self.holdTime - elapsed
|
||||
else
|
||||
resetAttributes(self)
|
||||
self:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(...)
|
||||
CastStart(...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Update(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Castbar
|
||||
if(element and unit and not unit:match('%wtarget$')) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_SPELLCAST_START', CastStart)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_START', CastStart)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_STOP', CastStop)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_STOP', CastStop)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_DELAYED', CastUpdate)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_UPDATE', CastUpdate)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_FAILED', CastFail)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_INTERRUPTED', CastFail)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_INTERRUPTIBLE', CastInterruptible)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_NOT_INTERRUPTIBLE', CastInterruptible)
|
||||
|
||||
-- ElvUI block
|
||||
self:RegisterEvent('UNIT_SPELLCAST_SENT', UNIT_SPELLCAST_SENT, true)
|
||||
-- end block
|
||||
|
||||
element.holdTime = 0
|
||||
|
||||
element:SetScript('OnUpdate', element.OnUpdate or onUpdate)
|
||||
|
||||
if(self.unit == 'player' and not (self.hasChildren or self.isChild)) then
|
||||
CastingBarFrame_SetUnit(CastingBarFrame, nil)
|
||||
CastingBarFrame_SetUnit(PetCastingBarFrame, nil)
|
||||
end
|
||||
|
||||
if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
|
||||
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
local spark = element.Spark
|
||||
if(spark and spark:IsObjectType('Texture') and not spark:GetTexture()) then
|
||||
spark:SetTexture([[Interface\CastingBar\UI-CastingBar-Spark]])
|
||||
end
|
||||
|
||||
local shield = element.Shield
|
||||
if(shield and shield:IsObjectType('Texture') and not shield:GetTexture()) then
|
||||
shield:SetTexture([[Interface\CastingBar\UI-CastingBar-Small-Shield]])
|
||||
end
|
||||
|
||||
local safeZone = element.SafeZone
|
||||
if(safeZone and safeZone:IsObjectType('Texture') and not safeZone:GetTexture()) then
|
||||
safeZone:SetColorTexture(1, 0, 0)
|
||||
end
|
||||
|
||||
element:Hide()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Castbar
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_START', CastStart)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_START', CastStart)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_DELAYED', CastUpdate)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_UPDATE', CastUpdate)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_STOP', CastStop)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_STOP', CastStop)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_FAILED', CastFail)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_INTERRUPTED', CastFail)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_INTERRUPTIBLE', CastInterruptible)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_NOT_INTERRUPTIBLE', CastInterruptible)
|
||||
|
||||
element:SetScript('OnUpdate', nil)
|
||||
|
||||
if(self.unit == 'player' and not (self.hasChildren or self.isChild)) then
|
||||
CastingBarFrame_OnLoad(CastingBarFrame, 'player', true, false)
|
||||
CastingBarFrame_SetUnit(CastingBarFrame, 'player', true, false)
|
||||
PetCastingBarFrame_OnLoad(PetCastingBarFrame)
|
||||
CastingBarFrame_SetUnit(PetCastingBarFrame, 'pet', false, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
hooksecurefunc('DoTradeSkill', function(_, num)
|
||||
tradeskillCurrent = 0
|
||||
tradeskillTotal = num or 1
|
||||
mergeTradeskill = true
|
||||
end)
|
||||
-- end block
|
||||
|
||||
oUF:AddElement('Castbar', Update, Enable, Disable)
|
||||
|
||||
function CastingBarFrame_SetUnit(self, unit, showTradeSkills, showShield)
|
||||
if(self.unit ~= unit) then
|
||||
self.unit = unit
|
||||
self.showTradeSkills = showTradeSkills
|
||||
self.showShield = showShield
|
||||
|
||||
self.casting = nil
|
||||
self.channeling = nil
|
||||
self.holdTime = 0
|
||||
self.fadeOut = nil
|
||||
|
||||
if(unit) then
|
||||
self:RegisterEvent("UNIT_SPELLCAST_START")
|
||||
self:RegisterEvent("UNIT_SPELLCAST_STOP")
|
||||
self:RegisterEvent("UNIT_SPELLCAST_FAILED")
|
||||
self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
|
||||
self:RegisterEvent("UNIT_SPELLCAST_DELAYED")
|
||||
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
|
||||
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
|
||||
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
|
||||
self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE")
|
||||
self:RegisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE")
|
||||
self:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
|
||||
CastingBarFrame_OnEvent(self, "PLAYER_ENTERING_WORLD")
|
||||
else
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED")
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_DELAYED")
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_START")
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE")
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE")
|
||||
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_START")
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_STOP")
|
||||
self:UnregisterEvent("UNIT_SPELLCAST_FAILED")
|
||||
|
||||
self:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,102 @@
|
||||
--[[
|
||||
# Element: Combat Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the player's combat status.
|
||||
|
||||
## Widget
|
||||
|
||||
CombatIndicator - Any UI widget.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local CombatIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
CombatIndicator:SetSize(16, 16)
|
||||
CombatIndicator:SetPoint('TOP', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.CombatIndicator = CombatIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local UnitAffectingCombat = UnitAffectingCombat
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.CombatIndicator
|
||||
|
||||
--[[ Callback: CombatIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the CombatIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local inCombat = UnitAffectingCombat('player')
|
||||
if(inCombat) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: CombatIndicator:PostUpdate(inCombat)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the CombatIndicator element
|
||||
* inCombat - indicates if the player is affecting combat (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(inCombat)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: CombatIndicator.Override(self, event)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
return (self.CombatIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.CombatIndicator
|
||||
if(element and unit == 'player') then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('PLAYER_REGEN_DISABLED', Path, true)
|
||||
self:RegisterEvent('PLAYER_REGEN_ENABLED', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\CharacterFrame\UI-StateIcon]])
|
||||
element:SetTexCoord(.5, 1, 0, .49)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.CombatIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('PLAYER_REGEN_DISABLED', Path)
|
||||
self:UnregisterEvent('PLAYER_REGEN_ENABLED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('CombatIndicator', Path, Enable, Disable)
|
||||
@@ -0,0 +1,127 @@
|
||||
--[[
|
||||
# Element: ComboPoints
|
||||
|
||||
Handles the visibility and updating of the player's combo points.
|
||||
|
||||
## Widget
|
||||
|
||||
ComboPoints - An `table` consisting of as many Textures as the theoretical maximum return of [GetComboPoints](http://wowprogramming.com/docs/api/GetComboPoints).
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
local ComboPoints = {}
|
||||
for index = 1, 10 do
|
||||
local Bar = CreateFrame('StatusBar', nil, self)
|
||||
|
||||
-- Position and size.
|
||||
Bar:SetSize(16, 16)
|
||||
Bar:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', (index - 1) * Bar:GetWidth(), 0)
|
||||
|
||||
ComboPoints[index] = Bar
|
||||
end
|
||||
|
||||
-- Register with oUF
|
||||
self.ComboPoints = ComboPoints
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local GetComboPoints = GetComboPoints
|
||||
local UnitHasVehicleUI = UnitHasVehicleUI
|
||||
|
||||
local MAX_COMBO_POINTS = MAX_COMBO_POINTS
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(unit == 'pet') then return end
|
||||
|
||||
local element = self.ComboPoints
|
||||
|
||||
--[[ Callback: ComboPoints:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the ComboPoints element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local cp
|
||||
if(UnitHasVehicleUI('player')) then
|
||||
cp = GetComboPoints('vehicle', 'target')
|
||||
else
|
||||
cp = GetComboPoints('player', 'target')
|
||||
end
|
||||
|
||||
for i = 1, MAX_COMBO_POINTS do
|
||||
if(i <= cp) then
|
||||
element[i]:Show()
|
||||
else
|
||||
element[i]:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: ComboPoints:PostUpdate(role)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the ComboPoints element
|
||||
* cpoint - the current amount of combo points (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(cp)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: ComboPoints.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.ComboPoints.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.ComboPoints
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_COMBO_POINTS', Path, true)
|
||||
self:RegisterEvent('PLAYER_TARGET_CHANGED', Path, true)
|
||||
|
||||
for index = 1, MAX_COMBO_POINTS do
|
||||
local cp = element[index]
|
||||
if(cp:IsObjectType('Texture') and not cp:GetTexture()) then
|
||||
cp:SetTexture([[Interface\ComboFrame\ComboPoint]])
|
||||
cp:SetTexCoord(0, 0.375, 0, 1)
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.ComboPoints
|
||||
if(element) then
|
||||
for index = 1, MAX_COMBO_POINTS do
|
||||
element[index]:Hide()
|
||||
end
|
||||
|
||||
self:UnregisterEvent('UNIT_COMBO_POINTS', Path)
|
||||
self:UnregisterEvent('PLAYER_TARGET_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('ComboPoints', Path, Enable, Disable)
|
||||
@@ -0,0 +1,107 @@
|
||||
--[[
|
||||
# Element: Group Role Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the unit's current group role (tank, healer or damager).
|
||||
|
||||
## Widget
|
||||
|
||||
GroupRoleIndicator - A `Texture` used to display the group role icon.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local GroupRoleIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
GroupRoleIndicator:SetSize(16, 16)
|
||||
GroupRoleIndicator:SetPoint('LEFT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.GroupRoleIndicator = GroupRoleIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local UnitGroupRolesAssigned = UnitGroupRolesAssigned
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.GroupRoleIndicator
|
||||
|
||||
--[[ Callback: GroupRoleIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the GroupRoleIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local isTank, isHealer, isDamage = UnitGroupRolesAssigned(self.unit)
|
||||
if(isTank or isHealer or isDamage) then
|
||||
local role = isTank and "tank" or isHealer and "healer" or isDamage and "dps"
|
||||
element:SetTexture("Interface\\AddOns\\ElvUI\\media\\textures\\" .. role)
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: GroupRoleIndicator:PostUpdate(role)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the GroupRoleIndicator element
|
||||
* isTank, isHealer, isDamage - the role as returned by [UnitGroupRolesAssigned](http://wowprogramming.com/docs/api/UnitGroupRolesAssigned)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(isTank, isHealer, isDamage)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: GroupRoleIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.GroupRoleIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.GroupRoleIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
if(self.unit == 'player') then
|
||||
self:RegisterEvent('PLAYER_ROLES_ASSIGNED', Path, true)
|
||||
else
|
||||
self:RegisterEvent('PARTY_MEMBERS_CHANGED', Path, true)
|
||||
end
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\LFGFrame\UI-LFG-ICON-PORTRAITROLES]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.GroupRoleIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('PLAYER_ROLES_ASSIGNED', Path)
|
||||
self:UnregisterEvent('PARTY_MEMBERS_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('GroupRoleIndicator', Path, Enable, Disable)
|
||||
@@ -0,0 +1,116 @@
|
||||
--[[
|
||||
# Element: HappinessIndicator
|
||||
|
||||
Handles the visibility and updating of player pet happiness.
|
||||
|
||||
## Widget
|
||||
|
||||
HappinessIndicator - A `Texture` used to display the current happiness level.
|
||||
The element works by changing the texture's vertex color.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local HappinessIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
HappinessIndicator:SetSize(16, 16)
|
||||
HappinessIndicator:SetPoint('TOPRIGHT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.HappinessIndicator = HappinessIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local GetPetHappiness = GetPetHappiness
|
||||
local HasPetUI = HasPetUI
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(not unit or self.unit ~= unit) then return end
|
||||
|
||||
local element = self.HappinessIndicator
|
||||
|
||||
--[[ Callback: HappinessIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the ComboPoints element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local _, hunterPet = HasPetUI()
|
||||
local happiness, damagePercentage = GetPetHappiness()
|
||||
|
||||
if(hunterPet and happiness) then
|
||||
if(happiness == 1) then
|
||||
element:SetTexCoord(0.375, 0.5625, 0, 0.359375)
|
||||
elseif(happiness == 2) then
|
||||
element:SetTexCoord(0.1875, 0.375, 0, 0.359375)
|
||||
elseif(happiness == 3) then
|
||||
element:SetTexCoord(0, 0.1875, 0, 0.359375)
|
||||
end
|
||||
|
||||
element:Show()
|
||||
else
|
||||
return element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: HappinessIndicator:PostUpdate(role)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the ComboPoints element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* happiness - the numerical happiness value of the pet (1 = unhappy, 2 = content, 3 = happy) (number)
|
||||
* damagePercentage - damage modifier, happiness affects this (unhappy = 75%, content = 100%, happy = 125%) (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, happiness, damagePercentage)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: HappinessIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.HappinessIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.HappinessIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_HAPPINESS', Path)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\PetPaperDollFrame\UI-PetHappiness]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.HappinessIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_HAPPINESS', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('HappinessIndicator', Path, Enable, Disable)
|
||||
@@ -0,0 +1,380 @@
|
||||
--[[
|
||||
# Element: Health Bar
|
||||
|
||||
Handles the updating of a status bar that displays the unit's health.
|
||||
|
||||
## Widget
|
||||
|
||||
Health - A `StatusBar` used to represent the unit's health.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.bg - A `Texture` used as a background. It will inherit the color of the main StatusBar.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
|
||||
|
||||
## Options
|
||||
|
||||
.frequentUpdates - Indicates whether to use OnUpdate script instead of UNIT_HEALTH to update the
|
||||
bar (boolean)
|
||||
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
|
||||
.considerSelectionInCombatHostile - Indicates whether selection should be considered hostile while the unit is in
|
||||
combat with the player (boolean)
|
||||
|
||||
The following options are listed by priority. The first check that returns true decides the color of the bar.
|
||||
|
||||
.colorDisconnected - Use `self.colors.disconnected` to color the bar if the unit is offline (boolean)
|
||||
.colorTapping - Use `self.colors.tapping` to color the bar if the unit isn't tapped by the player (boolean)
|
||||
.colorHappiness - Use `self.colors.happiness` to color the bar if the unit is pet based on pet happiness (boolean)
|
||||
.colorThreat - Use `self.colors.threat[threat]` to color the bar based on the unit's threat status. `threat` is
|
||||
defined by the first return of [UnitThreatSituation](https://wow.gamepedia.com/API_UnitThreatSituation) (boolean)
|
||||
.colorClass - Use `self.colors.class[class]` to color the bar based on unit class. `class` is defined by the
|
||||
second return of [UnitClass](http://wowprogramming.com/docs/api/UnitClass.html) (boolean)
|
||||
.colorClassNPC - Use `self.colors.class[class]` to color the bar if the unit is a NPC (boolean)
|
||||
.colorClassPet - Use `self.colors.class[class]` to color the bar if the unit is player controlled, but not a player
|
||||
(boolean)
|
||||
.colorReaction - Use `self.colors.reaction[reaction]` to color the bar based on the player's reaction towards the
|
||||
unit. `reaction` is defined by the return value of
|
||||
[UnitReaction](http://wowprogramming.com/docs/api/UnitReaction.html) (boolean)
|
||||
.colorSmooth - Use `smoothGradient` if present or `self.colors.smooth` to color the bar with a smooth gradient
|
||||
based on the player's current health percentage (boolean)
|
||||
.colorHealth - Use `self.colors.health` to color the bar. This flag is used to reset the bar color back to default
|
||||
if none of the above conditions are met (boolean)
|
||||
|
||||
## Sub-Widgets Options
|
||||
|
||||
.multiplier - Used to tint the background based on the main widgets R, G and B values. Defaults to 1 (number)[0-1]
|
||||
|
||||
## Attributes
|
||||
|
||||
.disconnected - Indicates whether the unit is disconnected (boolean)
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local Health = CreateFrame('StatusBar', nil, self)
|
||||
Health:SetHeight(20)
|
||||
Health:SetPoint('TOP')
|
||||
Health:SetPoint('LEFT')
|
||||
Health:SetPoint('RIGHT')
|
||||
|
||||
-- Add a background
|
||||
local Background = Health:CreateTexture(nil, 'BACKGROUND')
|
||||
Background:SetAllPoints(Health)
|
||||
Background:SetTexture(1, 1, 1, .5)
|
||||
|
||||
-- Options
|
||||
Health.frequentUpdates = true
|
||||
Health.colorTapping = true
|
||||
Health.colorDisconnected = true
|
||||
Health.colorClass = true
|
||||
Health.colorReaction = true
|
||||
Health.colorHealth = true
|
||||
|
||||
-- Make the background darker.
|
||||
Background.multiplier = .5
|
||||
|
||||
-- Register it with oUF
|
||||
Health.bg = Background
|
||||
self.Health = Health
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local function UpdateColor(self, event, unit)
|
||||
if(not unit or self.unit ~= unit) then return end
|
||||
local element = self.Health
|
||||
|
||||
local r, g, b, t
|
||||
if(element.colorDisconnected and element.disconnected) then
|
||||
t = self.colors.disconnected
|
||||
elseif(element.colorTapping and not UnitPlayerControlled(unit) and (UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) and not UnitIsTappedByAllThreatList(unit))) then
|
||||
t = self.colors.tapped
|
||||
elseif(element.colorHappiness and UnitIsUnit(unit, 'pet') and GetPetHappiness()) then
|
||||
t = self.colors.happiness[GetPetHappiness()]
|
||||
elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
|
||||
t = self.colors.threat[UnitThreatSituation('player', unit)]
|
||||
elseif(element.colorClass and UnitIsPlayer(unit)) or
|
||||
(element.colorClassNPC and not UnitIsPlayer(unit)) or
|
||||
(element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
|
||||
t = oUF.herocolor
|
||||
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
|
||||
t = self.colors.reaction[UnitReaction(unit, 'player')]
|
||||
elseif(element.colorSmooth) then
|
||||
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
|
||||
elseif(element.colorHealth) then
|
||||
t = self.colors.health
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
if(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = element.bg
|
||||
if(bg) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(unit, r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function ColorPath(self, ...)
|
||||
--[[ Override: Health.UpdateColor(self, event, unit)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Health.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(not unit or self.unit ~= unit) then return end
|
||||
local element = self.Health
|
||||
|
||||
--[[ Callback: Health:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Health element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local cur, max = UnitHealth(unit), UnitHealthMax(unit)
|
||||
local disconnected = not UnitIsConnected(unit)
|
||||
|
||||
element:SetMinMaxValues(0, max)
|
||||
|
||||
if(disconnected) then
|
||||
element:SetValue(max)
|
||||
else
|
||||
if(cur == 0) then
|
||||
cur = 0.0001
|
||||
end
|
||||
|
||||
element:SetValue(cur)
|
||||
end
|
||||
|
||||
element.cur = cur
|
||||
element.max = max
|
||||
element.disconnected = disconnected
|
||||
|
||||
--[[ Callback: Health:PostUpdate(unit, cur, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Health element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* cur - the unit's current health value (number)
|
||||
* max - the unit's maximum possible health value (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
element:PostUpdate(unit, cur, max)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Health.Override(self, event, unit)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Health.Override or Update) (self, ...);
|
||||
|
||||
ColorPath(self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
--[[ Health:SetColorDisconnected(state)
|
||||
Used to toggle coloring if the unit is offline.
|
||||
|
||||
* self - the Health element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorDisconnected(element, state)
|
||||
if(element.colorDisconnected ~= state) then
|
||||
element.colorDisconnected = state
|
||||
if(element.colorDisconnected) then
|
||||
element.__owner:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Health:SetColorHappiness(state)
|
||||
Used to toggle coloring by the unit's happiness.
|
||||
|
||||
* self - the Health element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorHappiness(element, state)
|
||||
if(element.colorHappiness ~= state) then
|
||||
element.colorHappiness = state
|
||||
if(element.colorHappiness) then
|
||||
element.__owner:RegisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Health:SetColorTapping(state)
|
||||
Used to toggle coloring if the unit isn't tapped by the player.
|
||||
|
||||
* self - the Health element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorTapping(element, state)
|
||||
if(element.colorTapping ~= state) then
|
||||
element.colorTapping = state
|
||||
if(element.colorTapping) then
|
||||
element.__owner:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Health:SetColorThreat(state)
|
||||
Used to toggle coloring by the unit's threat status.
|
||||
|
||||
* self - the Health element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorThreat(element, state)
|
||||
if(element.colorThreat ~= state) then
|
||||
element.colorThreat = state
|
||||
if(element.colorThreat) then
|
||||
element.__owner:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function onHealthUpdate(self)
|
||||
if(self.disconnected) then return end
|
||||
|
||||
local unit = self.__owner.unit
|
||||
local health = UnitHealth(unit)
|
||||
|
||||
if(health ~= self.health) then
|
||||
self.health = health
|
||||
|
||||
return Path(self.__owner, 'OnHealthUpdate', unit)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Health:SetFrequentUpdates(state)
|
||||
Used to toggle frequent updates.
|
||||
|
||||
* self - the Health element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetFrequentUpdates(element, state)
|
||||
if(element.frequentUpdates ~= state) then
|
||||
element.frequentUpdates = state
|
||||
if(element.frequentUpdates) then
|
||||
element:SetScript('OnUpdate', onHealthUpdate)
|
||||
|
||||
local unit = element.__owner.unit
|
||||
if((unit == 'party' or unit:match('party%d?$')) and not element:IsEventRegistered("UNIT_HEALTH")) then
|
||||
element:RegisterEvent('UNIT_HEALTH', Path)
|
||||
elseif(element:IsEventRegistered('UNIT_HEALTH')) then
|
||||
element:UnregisterEvent('UNIT_HEALTH', Path)
|
||||
end
|
||||
else
|
||||
element:SetScript('OnUpdate', nil)
|
||||
element.__owner:RegisterEvent('UNIT_HEALTH', Path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Health
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
element.SetColorDisconnected = SetColorDisconnected
|
||||
element.SetColorHappiness = SetColorHappiness
|
||||
element.SetColorTapping = SetColorTapping
|
||||
element.SetColorThreat = SetColorThreat
|
||||
element.SetFrequentUpdates = SetFrequentUpdates
|
||||
|
||||
if(element.colorDisconnected) then
|
||||
self:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorHappiness) then
|
||||
self:RegisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorTapping) then
|
||||
self:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorThreat) then
|
||||
self:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
|
||||
if(element.frequentUpdates and (unit and not unit:match('%w+target$'))) then
|
||||
element:SetScript('OnUpdate', onHealthUpdate)
|
||||
|
||||
-- The party frames need this to handle disconnect states correctly.
|
||||
if(unit == 'party') then
|
||||
self:RegisterEvent('UNIT_HEALTH', Path)
|
||||
end
|
||||
else
|
||||
self:RegisterEvent('UNIT_HEALTH', Path)
|
||||
end
|
||||
|
||||
self:RegisterEvent('UNIT_MAXHEALTH', Path)
|
||||
|
||||
if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
|
||||
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Health
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
if(element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', nil)
|
||||
end
|
||||
|
||||
self:UnregisterEvent('UNIT_HEALTH', Path)
|
||||
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
|
||||
self:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Health', Path, Enable, Disable)
|
||||
@@ -0,0 +1,107 @@
|
||||
--[[
|
||||
# Element: Leader Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the unit's leader status.
|
||||
|
||||
## Widget
|
||||
|
||||
LeaderIndicator - Any UI widget.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local LeaderIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
LeaderIndicator:SetSize(16, 16)
|
||||
LeaderIndicator:SetPoint('BOTTOM', self, 'TOP')
|
||||
|
||||
-- Register it with oUF
|
||||
self.LeaderIndicator = LeaderIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local UnitInParty = UnitInParty
|
||||
local UnitInRaid = UnitInRaid
|
||||
local UnitIsPartyLeader = UnitIsPartyLeader
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.LeaderIndicator
|
||||
|
||||
--[[ Callback: LeaderIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the LeaderIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local unit = self.unit
|
||||
local isLeader = (UnitInParty(unit) or UnitInRaid(unit)) and UnitIsPartyLeader(unit)
|
||||
if(isLeader) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: LeaderIndicator:PostUpdate(isLeader)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the LeaderIndicator element
|
||||
* isLeader - indicates whether the element is shown (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(isLeader)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: LeaderIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.LeaderIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.LeaderIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('PARTY_LEADER_CHANGED', Path, true)
|
||||
self:RegisterEvent('PARTY_MEMBERS_CHANGED', Path, true)
|
||||
self:RegisterEvent('RAID_ROSTER_UPDATE', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\GroupFrame\UI-Group-LeaderIcon]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.LeaderIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('PARTY_LEADER_CHANGED', Path)
|
||||
self:UnregisterEvent('PARTY_MEMBERS_CHANGED', Path)
|
||||
self:UnregisterEvent('RAID_ROSTER_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('LeaderIndicator', Path, Enable, Disable)
|
||||
@@ -0,0 +1,124 @@
|
||||
--[[
|
||||
# Element: Master Looter Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the unit's master looter status.
|
||||
|
||||
## Widget
|
||||
|
||||
MasterLooterIndicator - Any UI widget.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local MasterLooterIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
MasterLooterIndicator:SetSize(16, 16)
|
||||
MasterLooterIndicator:SetPoint('TOPRIGHT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.MasterLooterIndicator = MasterLooterIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local GetLootMethod = GetLootMethod
|
||||
local UnitInParty = UnitInParty
|
||||
local UnitInRaid = UnitInRaid
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
|
||||
local function Update(self, event)
|
||||
local unit = self.unit
|
||||
local element = self.MasterLooterIndicator
|
||||
|
||||
--[[ Callback: MasterLooterIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the MasterLooterIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local isShown = false
|
||||
if(UnitInParty(unit) or UnitInRaid(unit)) then
|
||||
local method, partyIndex, raidIndex = GetLootMethod()
|
||||
if(method == 'master') then
|
||||
local mlUnit
|
||||
if(partyIndex) then
|
||||
if(partyIndex == 0) then
|
||||
mlUnit = 'player'
|
||||
else
|
||||
mlUnit = 'party' .. partyIndex
|
||||
end
|
||||
elseif(raidIndex) then
|
||||
mlUnit = 'raid' .. raidIndex
|
||||
end
|
||||
|
||||
isShown = mlUnit and UnitIsUnit(unit, mlUnit)
|
||||
end
|
||||
end
|
||||
|
||||
if isShown then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: MasterLooterIndicator:PostUpdate(isShown)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the MasterLooterIndicator element
|
||||
* isShown - indicates whether the element is shown (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(isShown)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: MasterLooterIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.MasterLooterIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.MasterLooterIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('PARTY_LOOT_METHOD_CHANGED', Path, true)
|
||||
self:RegisterEvent('PARTY_MEMBERS_CHANGED', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\GroupFrame\UI-Group-MasterLooter]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.MasterLooterIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('PARTY_LOOT_METHOD_CHANGED', Path)
|
||||
self:UnregisterEvent('PARTY_MEMBERS_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('MasterLooterIndicator', Path, Enable, Disable)
|
||||
@@ -0,0 +1,148 @@
|
||||
--[[
|
||||
# Element: Portraits
|
||||
|
||||
Handles the updating of the unit's portrait.
|
||||
|
||||
## Widget
|
||||
|
||||
Portrait - A `PlayerModel` or a `Texture` used to represent the unit's portrait.
|
||||
|
||||
## Notes
|
||||
|
||||
A question mark model will be used if the widget is a PlayerModel and the client doesn't have the model information for
|
||||
the unit.
|
||||
|
||||
## Examples
|
||||
|
||||
-- 3D Portrait
|
||||
-- Position and size
|
||||
local Portrait = CreateFrame('PlayerModel', nil, self)
|
||||
Portrait:SetSize(32, 32)
|
||||
Portrait:SetPoint('RIGHT', self, 'LEFT')
|
||||
|
||||
-- Register it with oUF
|
||||
self.Portrait = Portrait
|
||||
|
||||
-- 2D Portrait
|
||||
local Portrait = self:CreateTexture(nil, 'OVERLAY')
|
||||
Portrait:SetSize(32, 32)
|
||||
Portrait:SetPoint('RIGHT', self, 'LEFT')
|
||||
|
||||
-- Register it with oUF
|
||||
self.Portrait = Portrait
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local SetPortraitTexture = SetPortraitTexture
|
||||
local UnitExists = UnitExists
|
||||
local UnitGUID = UnitGUID
|
||||
local UnitIsConnected = UnitIsConnected
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local UnitIsVisible = UnitIsVisible
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(not unit or not UnitIsUnit(self.unit, unit)) then return end
|
||||
|
||||
local element = self.Portrait
|
||||
|
||||
--[[ Callback: Portrait:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Portrait element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then element:PreUpdate(unit) end
|
||||
|
||||
local guid = UnitGUID(unit)
|
||||
local isAvailable = UnitIsConnected(unit) and UnitIsVisible(unit)
|
||||
if(event ~= 'OnUpdate' or element.guid ~= guid or element.state ~= isAvailable) then
|
||||
if(element:IsObjectType('PlayerModel')) then
|
||||
if(not isAvailable) then
|
||||
element:SetModelScale(4.25)
|
||||
element:SetCamera(0)
|
||||
element:SetPosition(0, 0, -1.5)
|
||||
element:SetModel([[Interface\Buttons\TalkToMeQuestionMark.m2]])
|
||||
elseif(element.guid ~= guid or event == 'UNIT_MODEL_CHANGED') then
|
||||
element:ClearModel()
|
||||
element:SetUnit(unit)
|
||||
element:SetModelScale(1)
|
||||
element:SetCamera(0)
|
||||
element:SetPosition(0, 0, 0)
|
||||
else
|
||||
element:SetCamera(0)
|
||||
end
|
||||
else
|
||||
SetPortraitTexture(element, unit)
|
||||
end
|
||||
|
||||
element.guid = guid
|
||||
element.state = isAvailable
|
||||
end
|
||||
|
||||
--[[ Callback: Portrait:PostUpdate(unit)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Portrait element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Portrait.Override(self, event, unit)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
return (self.Portrait.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Portrait
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_PORTRAIT_UPDATE', Path)
|
||||
self:RegisterEvent('UNIT_MODEL_CHANGED', Path)
|
||||
self:RegisterEvent('UNIT_CONNECTION', Path)
|
||||
|
||||
-- The quest log uses PARTY_MEMBER_{ENABLE,DISABLE} to handle updating of
|
||||
-- party members overlapping quests. This will probably be enough to handle
|
||||
-- model updating.
|
||||
--
|
||||
-- DISABLE isn't used as it fires when we most likely don't have the
|
||||
-- information we want.
|
||||
if(unit == 'party') then
|
||||
self:RegisterEvent('PARTY_MEMBER_ENABLE', Path)
|
||||
end
|
||||
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Portrait
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_PORTRAIT_UPDATE', Path)
|
||||
self:UnregisterEvent('UNIT_MODEL_CHANGED', Path)
|
||||
self:UnregisterEvent('PARTY_MEMBER_ENABLE', Path)
|
||||
self:UnregisterEvent('UNIT_CONNECTION', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Portrait', Path, Enable, Disable)
|
||||
@@ -0,0 +1,427 @@
|
||||
--[[
|
||||
# Element: Power Bar
|
||||
|
||||
Handles the updating of a status bar that displays the unit's power.
|
||||
|
||||
## Widget
|
||||
|
||||
Power - A `StatusBar` used to represent the unit's power.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.bg - A `Texture` used as a background. It will inherit the color of the main StatusBar.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a StatusBar and doesn't have a texture or a color set.
|
||||
|
||||
## Options
|
||||
|
||||
.frequentUpdates - Indicates whether to use OnUpdate script instead of UNIT_POWER to update the bar. Only valid for the
|
||||
player and pet units (boolean)
|
||||
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
|
||||
|
||||
The following options are listed by priority. The first check that returns true decides the color of the bar.
|
||||
|
||||
.colorTapping - Use `self.colors.tapping` to color the bar if the unit isn't tapped by the player (boolean)
|
||||
.colorDisconnected - Use `self.colors.disconnected` to color the bar if the unit is offline (boolean)
|
||||
.colorHappiness - Use `self.colors.happiness` to color the bar if the unit is pet based on pet happiness (boolean)
|
||||
.colorPower - Use `self.colors.power[token]` to color the bar based on the unit's power type. This method will
|
||||
fall-back to `:GetAlternativeColor()` if it can't find a color matching the token. If this function
|
||||
isn't defined, then it will attempt to color based upon the alternative power colors returned by
|
||||
[UnitPowerType](http://wowprogramming.com/docs/api/UnitPowerType). Finally, if these aren't
|
||||
defined, then it will attempt to color the bar based upon `self.colors.power[type]` (boolean)
|
||||
.colorClass - Use `self.colors.class[class]` to color the bar based on unit class. `class` is defined by the
|
||||
second return of [UnitClass](http://wowprogramming.com/docs/api/UnitClass) (boolean)
|
||||
.colorClassNPC - Use `self.colors.class[class]` to color the bar if the unit is a NPC (boolean)
|
||||
.colorClassPet - Use `self.colors.class[class]` to color the bar if the unit is player controlled, but not a player
|
||||
(boolean)
|
||||
.colorReaction - Use `self.colors.reaction[reaction]` to color the bar based on the player's reaction towards the
|
||||
unit. `reaction` is defined by the return value of
|
||||
[UnitReaction](http://wowprogramming.com/docs/api/UnitReaction) (boolean)
|
||||
.colorSmooth - Use `smoothGradient` if present or `self.colors.smooth` to color the bar with a smooth gradient
|
||||
based on the player's current power percentage (boolean)
|
||||
|
||||
## Sub-Widget Options
|
||||
|
||||
.multiplier - A multiplier used to tint the background based on the main widgets R, G and B values. Defaults to 1
|
||||
(number)[0-1]
|
||||
|
||||
## Attributes
|
||||
|
||||
.disconnected - Indicates whether the unit is disconnected (boolean)
|
||||
.tapped - Indicates whether the unit is tapped by the player (boolean)
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local Power = CreateFrame('StatusBar', nil, self)
|
||||
Power:SetHeight(20)
|
||||
Power:SetPoint('BOTTOM')
|
||||
Power:SetPoint('LEFT')
|
||||
Power:SetPoint('RIGHT')
|
||||
|
||||
-- Add a background
|
||||
local Background = Power:CreateTexture(nil, 'BACKGROUND')
|
||||
Background:SetAllPoints(Power)
|
||||
Background:SetTexture(1, 1, 1, .5)
|
||||
|
||||
-- Options
|
||||
Power.frequentUpdates = true
|
||||
Power.colorTapping = true
|
||||
Power.colorDisconnected = true
|
||||
Power.colorPower = true
|
||||
Power.colorClass = true
|
||||
Power.colorReaction = true
|
||||
|
||||
-- Make the background darker.
|
||||
Background.multiplier = .5
|
||||
|
||||
-- Register it with oUF
|
||||
Power.bg = Background
|
||||
self.Power = Power
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local unpack = unpack
|
||||
|
||||
local GetPetHappiness = GetPetHappiness
|
||||
local UnitIsConnected = UnitIsConnected
|
||||
local UnitIsPlayer = UnitIsPlayer
|
||||
local UnitIsTapped = UnitIsTapped
|
||||
local UnitIsTappedByPlayer = UnitIsTappedByPlayer
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local UnitPlayerControlled = UnitPlayerControlled
|
||||
local UnitPower = UnitPower
|
||||
local UnitPowerMax = UnitPowerMax
|
||||
local UnitPowerType = UnitPowerType
|
||||
local UnitReaction = UnitReaction
|
||||
|
||||
local function UpdateColor(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
local element = self.Power
|
||||
|
||||
local ptype, ptoken, altR, altG, altB = UnitPowerType(unit)
|
||||
local r, g, b, t
|
||||
if(element.colorDisconnected and element.disconnected) then
|
||||
t = self.colors.disconnected
|
||||
elseif(element.colorTapping and not UnitPlayerControlled(unit) and (UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) and not UnitIsTappedByAllThreatList(unit))) then
|
||||
t = self.colors.tapped
|
||||
elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
|
||||
t = self.colors.threat[UnitThreatSituation('player', unit)]
|
||||
elseif(element.colorHappiness and UnitIsUnit(unit, 'pet') and GetPetHappiness()) then
|
||||
t = self.colors.happiness[GetPetHappiness()]
|
||||
elseif(element.colorPower) then
|
||||
t = self.colors.power[ptoken or ptype]
|
||||
if(not t) then
|
||||
if(element.GetAlternativeColor) then
|
||||
r, g, b = element:GetAlternativeColor(unit, ptype, ptoken, altR, altG, altB)
|
||||
elseif(altR) then
|
||||
r, g, b = altR, altG, altB
|
||||
end
|
||||
end
|
||||
elseif(element.colorClass and UnitIsPlayer(unit)) or
|
||||
(element.colorClassNPC and not UnitIsPlayer(unit)) or
|
||||
(element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
|
||||
t = oUF.herocolor
|
||||
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
|
||||
t = self.colors.reaction[UnitReaction(unit, 'player')]
|
||||
elseif(element.colorSmooth) then
|
||||
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
element:SetStatusBarTexture(element.texture)
|
||||
|
||||
if(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
end
|
||||
|
||||
local bg = element.bg
|
||||
if(bg and b) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(unit, r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function ColorPath(self, ...)
|
||||
--[[ Override: Power.UpdateColor(self, event, unit)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Power.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
local element = self.Power
|
||||
|
||||
--[[ Callback: Power:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Power element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local cur, max = UnitPower(unit), UnitPowerMax(unit)
|
||||
local disconnected = not UnitIsConnected(unit)
|
||||
if max == 0 then
|
||||
max = 1
|
||||
end
|
||||
|
||||
element:SetMinMaxValues(0, max)
|
||||
|
||||
if(disconnected) then
|
||||
element:SetValue(max)
|
||||
else
|
||||
element:SetValue(cur)
|
||||
end
|
||||
|
||||
element.cur = cur
|
||||
element.max = max
|
||||
element.disconnected = disconnected
|
||||
|
||||
--[[ Callback: Power:PostUpdate(unit, cur, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Power element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* cur - the unit's current power value (number)
|
||||
* max - the unit's maximum possible power value (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
element:PostUpdate(unit, cur, max)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Power.Override(self, event, unit, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.Power.Override or Update) (self, ...);
|
||||
|
||||
ColorPath(self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
--[[ Power:SetColorDisconnected(state)
|
||||
Used to toggle coloring if the unit is offline.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorDisconnected(element, state)
|
||||
if(element.colorDisconnected ~= state) then
|
||||
element.colorDisconnected = state
|
||||
if(element.colorDisconnected) then
|
||||
element.__owner:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Power:SetColorTapping(state)
|
||||
Used to toggle coloring if the unit isn't tapped by the player.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorTapping(element, state)
|
||||
if(element.colorTapping ~= state) then
|
||||
element.colorTapping = state
|
||||
if(element.colorTapping) then
|
||||
element.__owner:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Power:SetColorThreat(state)
|
||||
Used to toggle coloring by the unit's threat status.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorThreat(element, state)
|
||||
if(element.colorThreat ~= state) then
|
||||
element.colorThreat = state
|
||||
if(element.colorThreat) then
|
||||
element.__owner:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Power:SetColorHappiness(state)
|
||||
Used to toggle coloring by the unit's happiness status.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorHappiness(element, state)
|
||||
if(element.colorHappiness ~= state) then
|
||||
element.colorHappiness = state
|
||||
if(element.colorHappiness) then
|
||||
element.__owner:RegisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function onPowerUpdate(self)
|
||||
if(self.disconnected) then return end
|
||||
|
||||
local unit = self.__owner.unit
|
||||
local power = UnitPower(unit)
|
||||
|
||||
if(power ~= self.power) then
|
||||
self.power = power
|
||||
|
||||
return Path(self.__owner, 'OnPowerUpdate', unit)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Power:SetFrequentUpdates(state)
|
||||
Used to toggle frequent updates.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetFrequentUpdates(element, state)
|
||||
--if(not unit or (unit ~= 'player' and unit ~= 'pet')) then return end
|
||||
|
||||
if(element.frequentUpdates ~= state) then
|
||||
element.frequentUpdates = state
|
||||
if(element.frequentUpdates and not element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', onPowerUpdate)
|
||||
|
||||
element.__owner:UnregisterEvent('UNIT_MANA', Path)
|
||||
element.__owner:UnregisterEvent('UNIT_RAGE', Path)
|
||||
element.__owner:UnregisterEvent('UNIT_FOCUS', Path)
|
||||
element.__owner:UnregisterEvent('UNIT_ENERGY', Path)
|
||||
element.__owner:UnregisterEvent('UNIT_RUNIC_POWER', Path)
|
||||
elseif(not element.frequentUpdates and element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', nil)
|
||||
|
||||
element.__owner:RegisterEvent('UNIT_MANA', Path)
|
||||
element.__owner:RegisterEvent('UNIT_RAGE', Path)
|
||||
element.__owner:RegisterEvent('UNIT_FOCUS', Path)
|
||||
element.__owner:RegisterEvent('UNIT_ENERGY', Path)
|
||||
element.__owner:RegisterEvent('UNIT_RUNIC_POWER', Path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Power
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
element.SetColorDisconnected = SetColorDisconnected
|
||||
element.SetColorTapping = SetColorTapping
|
||||
element.SetColorThreat = SetColorThreat
|
||||
element.SetColorHappiness = SetColorHappiness
|
||||
element.SetFrequentUpdates = SetFrequentUpdates
|
||||
|
||||
if(element.colorDisconnected) then
|
||||
self:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorTapping) then
|
||||
self:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorThreat) then
|
||||
self:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorHappiness) then
|
||||
self:RegisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
|
||||
if(element.frequentUpdates and (unit == 'player' or unit == 'pet')) then
|
||||
element:SetScript('OnUpdate', onPowerUpdate)
|
||||
else
|
||||
self:RegisterEvent('UNIT_MANA', Path)
|
||||
self:RegisterEvent('UNIT_RAGE', Path)
|
||||
self:RegisterEvent('UNIT_FOCUS', Path)
|
||||
self:RegisterEvent('UNIT_ENERGY', Path)
|
||||
self:RegisterEvent('UNIT_RUNIC_POWER', Path)
|
||||
end
|
||||
|
||||
self:RegisterEvent('UNIT_MAXMANA', Path)
|
||||
self:RegisterEvent('UNIT_MAXRAGE', Path)
|
||||
self:RegisterEvent('UNIT_MAXFOCUS', Path)
|
||||
self:RegisterEvent('UNIT_MAXENERGY', Path)
|
||||
self:RegisterEvent('UNIT_MAXRUNIC_POWER', Path)
|
||||
self:RegisterEvent('UNIT_DISPLAYPOWER', Path)
|
||||
|
||||
if(element:IsObjectType('StatusBar')) then
|
||||
element.texture = element:GetStatusBarTexture() and element:GetStatusBarTexture():GetTexture() or [[Interface\TargetingFrame\UI-StatusBar]]
|
||||
element:SetStatusBarTexture(element.texture)
|
||||
end
|
||||
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Power
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
if(element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', nil)
|
||||
else
|
||||
self:UnregisterEvent('UNIT_MANA', Path)
|
||||
self:UnregisterEvent('UNIT_RAGE', Path)
|
||||
self:UnregisterEvent('UNIT_FOCUS', Path)
|
||||
self:UnregisterEvent('UNIT_ENERGY', Path)
|
||||
self:UnregisterEvent('UNIT_RUNIC_POWER', Path)
|
||||
end
|
||||
|
||||
self:UnregisterEvent('UNIT_MAXMANA', Path)
|
||||
self:UnregisterEvent('UNIT_MAXRAGE', Path)
|
||||
self:UnregisterEvent('UNIT_MAXFOCUS', Path)
|
||||
self:UnregisterEvent('UNIT_MAXENERGY', Path)
|
||||
self:UnregisterEvent('UNIT_MAXRUNIC_POWER', Path)
|
||||
self:UnregisterEvent('UNIT_DISPLAYPOWER', Path)
|
||||
|
||||
self:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
self:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Power', Path, Enable, Disable)
|
||||
@@ -0,0 +1,321 @@
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local unpack = unpack
|
||||
|
||||
local GetPetHappiness = GetPetHappiness
|
||||
local UnitClass = UnitClass
|
||||
local UnitIsConnected = UnitIsConnected
|
||||
local UnitIsPlayer = UnitIsPlayer
|
||||
local UnitIsTapped = UnitIsTapped
|
||||
local UnitIsTappedByPlayer = UnitIsTappedByPlayer
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local UnitPlayerControlled = UnitPlayerControlled
|
||||
local UnitPower = UnitPower
|
||||
local UnitPowerMax = UnitPowerMax
|
||||
local UnitPowerType = UnitPowerType
|
||||
local UnitReaction = UnitReaction
|
||||
|
||||
local function UpdateColor(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
local element = self.Energy
|
||||
|
||||
local ptype, ptoken, altR, altG, altB = UnitPowerType(unit)
|
||||
local r, g, b
|
||||
local t = self.colors.power["ENERGY"]
|
||||
if(element.colorDisconnected and element.disconnected) then
|
||||
t = self.colors.disconnected
|
||||
elseif(element.colorTapping and not UnitPlayerControlled(unit) and (UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) and not UnitIsTappedByAllThreatList(unit))) then
|
||||
t = self.colors.tapped
|
||||
elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
|
||||
t = self.colors.threat[UnitThreatSituation('player', unit)]
|
||||
elseif(element.colorHappiness and UnitIsUnit(unit, 'pet') and GetPetHappiness()) then
|
||||
t = self.colors.happiness[GetPetHappiness()]
|
||||
elseif(element.colorPower) then
|
||||
t = self.colors.power[ptoken or ptype]
|
||||
if(not t) then
|
||||
if(element.GetAlternativeColor) then
|
||||
r, g, b = element:GetAlternativeColor(unit, ptype, ptoken, altR, altG, altB)
|
||||
elseif(altR) then
|
||||
r, g, b = altR, altG, altB
|
||||
end
|
||||
end
|
||||
elseif(element.colorClass and UnitIsPlayer(unit)) or
|
||||
(element.colorClassNPC and not UnitIsPlayer(unit)) or
|
||||
(element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
|
||||
local _, class = UnitClass(unit)
|
||||
t = self.colors.class[class]
|
||||
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
|
||||
t = self.colors.reaction[UnitReaction(unit, 'player')]
|
||||
elseif(element.colorSmooth) then
|
||||
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
element:SetStatusBarTexture(element.texture)
|
||||
|
||||
if(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
end
|
||||
|
||||
local bg = element.bg
|
||||
if(bg and b) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(unit, r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function ColorPath(self, ...)
|
||||
--[[ Override: Energy.UpdateColor(self, event, unit)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Energy.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
local element = self.Energy
|
||||
|
||||
--[[ Callback: Energy:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Energy element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local cur, max = UnitPower(unit, 3), UnitPowerMax(unit, 3)
|
||||
local disconnected = not UnitIsConnected(unit)
|
||||
if max == 0 then
|
||||
max = 1
|
||||
end
|
||||
|
||||
element:SetMinMaxValues(0, max)
|
||||
|
||||
if(disconnected) then
|
||||
element:SetValue(max)
|
||||
else
|
||||
element:SetValue(cur)
|
||||
end
|
||||
|
||||
element.cur = cur
|
||||
element.max = max
|
||||
element.disconnected = disconnected
|
||||
|
||||
--[[ Callback: Energy:PostUpdate(unit, cur, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Energy element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* cur - the unit's current energy value (number)
|
||||
* max - the unit's maximum possible energy value (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
element:PostUpdate(unit, cur, max)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Energy.Override(self, event, unit, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.Energy.Override or Update) (self, ...);
|
||||
|
||||
ColorPath(self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
--[[ Energy:SetColorDisconnected(state)
|
||||
Used to toggle coloring if the unit is offline.
|
||||
|
||||
* self - the Energy element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorDisconnected(element, state)
|
||||
if(element.colorDisconnected ~= state) then
|
||||
element.colorDisconnected = state
|
||||
if(element.colorDisconnected) then
|
||||
element.__owner:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Energy:SetColorTapping(state)
|
||||
Used to toggle coloring if the unit isn't tapped by the player.
|
||||
|
||||
* self - the Energy element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorTapping(element, state)
|
||||
if(element.colorTapping ~= state) then
|
||||
element.colorTapping = state
|
||||
if(element.colorTapping) then
|
||||
element.__owner:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Energy:SetColorThreat(state)
|
||||
Used to toggle coloring by the unit's threat status.
|
||||
|
||||
* self - the Energy element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorThreat(element, state)
|
||||
if(element.colorThreat ~= state) then
|
||||
element.colorThreat = state
|
||||
if(element.colorThreat) then
|
||||
element.__owner:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Energy:SetColorHappiness(state)
|
||||
Used to toggle coloring by the unit's happiness status.
|
||||
|
||||
* self - the Energy element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorHappiness(element, state)
|
||||
if(element.colorHappiness ~= state) then
|
||||
element.colorHappiness = state
|
||||
if(element.colorHappiness) then
|
||||
element.__owner:RegisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function onEnergyUpdate(self)
|
||||
if(self.disconnected) then return end
|
||||
|
||||
local unit = self.__owner.unit
|
||||
local energy = UnitPower(unit, 3)
|
||||
|
||||
if(energy ~= self.energy) then
|
||||
self.energy = energy
|
||||
|
||||
return Path(self.__owner, 'OnEnergyUpdate', unit)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Energy:SetFrequentUpdates(state)
|
||||
Used to toggle frequent updates.
|
||||
|
||||
* self - the Energy element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetFrequentUpdates(element, state)
|
||||
--if(not unit or (unit ~= 'player' and unit ~= 'pet')) then return end
|
||||
|
||||
if(element.frequentUpdates ~= state) then
|
||||
element.frequentUpdates = state
|
||||
if(element.frequentUpdates and not element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', onEnergyUpdate)
|
||||
|
||||
element.__owner:UnregisterEvent('UNIT_ENERGY', Path)
|
||||
elseif(not element.frequentUpdates and element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', nil)
|
||||
|
||||
element.__owner:RegisterEvent('UNIT_ENERGY_FREQUENT', Path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Energy
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
element.SetColorDisconnected = SetColorDisconnected
|
||||
element.SetColorTapping = SetColorTapping
|
||||
element.SetColorThreat = SetColorThreat
|
||||
element.SetColorHappiness = SetColorHappiness
|
||||
element.SetFrequentUpdates = SetFrequentUpdates
|
||||
|
||||
if(element.colorDisconnected) then
|
||||
self:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorTapping) then
|
||||
self:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorThreat) then
|
||||
self:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorHappiness) then
|
||||
self:RegisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
|
||||
-- if(element.frequentUpdates and (unit == 'player' or unit == 'pet')) then
|
||||
if((unit == 'player' or unit == 'pet')) then
|
||||
element:SetScript('OnUpdate', onEnergyUpdate)
|
||||
else
|
||||
self:RegisterEvent('UNIT_ENERGY', Path)
|
||||
end
|
||||
|
||||
self:RegisterEvent('UNIT_MAXENERGY', Path)
|
||||
|
||||
if(element:IsObjectType('StatusBar')) then
|
||||
element.texture = element:GetStatusBarTexture() and element:GetStatusBarTexture():GetTexture() or [[Interface\TargetingFrame\UI-StatusBar]]
|
||||
element:SetStatusBarTexture(element.texture)
|
||||
end
|
||||
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Energy
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
if(element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', nil)
|
||||
else
|
||||
self:UnregisterEvent('UNIT_ENERGY', Path)
|
||||
end
|
||||
|
||||
self:UnregisterEvent('UNIT_MAXENERGY', Path)
|
||||
|
||||
self:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
self:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Energy', Path, Enable, Disable)
|
||||
@@ -0,0 +1,321 @@
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local unpack = unpack
|
||||
|
||||
local GetPetHappiness = GetPetHappiness
|
||||
local UnitClass = UnitClass
|
||||
local UnitIsConnected = UnitIsConnected
|
||||
local UnitIsPlayer = UnitIsPlayer
|
||||
local UnitIsTapped = UnitIsTapped
|
||||
local UnitIsTappedByPlayer = UnitIsTappedByPlayer
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local UnitPlayerControlled = UnitPlayerControlled
|
||||
local UnitPower = UnitPower
|
||||
local UnitPowerMax = UnitPowerMax
|
||||
local UnitPowerType = UnitPowerType
|
||||
local UnitReaction = UnitReaction
|
||||
|
||||
local function UpdateColor(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
local element = self.Rage
|
||||
|
||||
local ptype, ptoken, altR, altG, altB = UnitPowerType(unit)
|
||||
local r, g, b
|
||||
local t = self.colors.power["RAGE"]
|
||||
if(element.colorDisconnected and element.disconnected) then
|
||||
t = self.colors.disconnected
|
||||
elseif(element.colorTapping and not UnitPlayerControlled(unit) and (UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) and not UnitIsTappedByAllThreatList(unit))) then
|
||||
t = self.colors.tapped
|
||||
elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
|
||||
t = self.colors.threat[UnitThreatSituation('player', unit)]
|
||||
elseif(element.colorHappiness and UnitIsUnit(unit, 'pet') and GetPetHappiness()) then
|
||||
t = self.colors.happiness[GetPetHappiness()]
|
||||
elseif(element.colorPower) then
|
||||
t = self.colors.power[ptoken or ptype]
|
||||
if(not t) then
|
||||
if(element.GetAlternativeColor) then
|
||||
r, g, b = element:GetAlternativeColor(unit, ptype, ptoken, altR, altG, altB)
|
||||
elseif(altR) then
|
||||
r, g, b = altR, altG, altB
|
||||
end
|
||||
end
|
||||
elseif(element.colorClass and UnitIsPlayer(unit)) or
|
||||
(element.colorClassNPC and not UnitIsPlayer(unit)) or
|
||||
(element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
|
||||
local _, class = UnitClass(unit)
|
||||
t = self.colors.class[class]
|
||||
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
|
||||
t = self.colors.reaction[UnitReaction(unit, 'player')]
|
||||
elseif(element.colorSmooth) then
|
||||
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
element:SetStatusBarTexture(element.texture)
|
||||
|
||||
if(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
end
|
||||
|
||||
local bg = element.bg
|
||||
if(bg and b) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(unit, r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function ColorPath(self, ...)
|
||||
--[[ Override: Rage.UpdateColor(self, event, unit)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Rage.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
local element = self.Rage
|
||||
|
||||
--[[ Callback: Rage:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Rage element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local cur, max = UnitPower(unit, 1), UnitPowerMax(unit, 1)
|
||||
local disconnected = not UnitIsConnected(unit)
|
||||
if max == 0 then
|
||||
max = 1
|
||||
end
|
||||
|
||||
element:SetMinMaxValues(0, max)
|
||||
|
||||
if(disconnected) then
|
||||
element:SetValue(max)
|
||||
else
|
||||
element:SetValue(cur)
|
||||
end
|
||||
|
||||
element.cur = cur
|
||||
element.max = max
|
||||
element.disconnected = disconnected
|
||||
|
||||
--[[ Callback: Rage:PostUpdate(unit, cur, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Rage element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* cur - the unit's current rage value (number)
|
||||
* max - the unit's maximum possible rage value (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
element:PostUpdate(unit, cur, max)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Rage.Override(self, event, unit, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.Rage.Override or Update) (self, ...);
|
||||
|
||||
ColorPath(self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
--[[ Rage:SetColorDisconnected(state)
|
||||
Used to toggle coloring if the unit is offline.
|
||||
|
||||
* self - the Rage element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorDisconnected(element, state)
|
||||
if(element.colorDisconnected ~= state) then
|
||||
element.colorDisconnected = state
|
||||
if(element.colorDisconnected) then
|
||||
element.__owner:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Rage:SetColorTapping(state)
|
||||
Used to toggle coloring if the unit isn't tapped by the player.
|
||||
|
||||
* self - the Rage element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorTapping(element, state)
|
||||
if(element.colorTapping ~= state) then
|
||||
element.colorTapping = state
|
||||
if(element.colorTapping) then
|
||||
element.__owner:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Rage:SetColorThreat(state)
|
||||
Used to toggle coloring by the unit's threat status.
|
||||
|
||||
* self - the Rage element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorThreat(element, state)
|
||||
if(element.colorThreat ~= state) then
|
||||
element.colorThreat = state
|
||||
if(element.colorThreat) then
|
||||
element.__owner:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Rage:SetColorHappiness(state)
|
||||
Used to toggle coloring by the unit's happiness status.
|
||||
|
||||
* self - the Rage element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetColorHappiness(element, state)
|
||||
if(element.colorHappiness ~= state) then
|
||||
element.colorHappiness = state
|
||||
if(element.colorHappiness) then
|
||||
element.__owner:RegisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function onRageUpdate(self)
|
||||
if(self.disconnected) then return end
|
||||
|
||||
local unit = self.__owner.unit
|
||||
local rage = UnitPower(unit, 1)
|
||||
|
||||
if(rage ~= self.rage) then
|
||||
self.rage = rage
|
||||
|
||||
return Path(self.__owner, 'OnRageUpdate', unit)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Rage:SetFrequentUpdates(state)
|
||||
Used to toggle frequent updates.
|
||||
|
||||
* self - the Rage element
|
||||
* state - the desired state (boolean)
|
||||
--]]
|
||||
local function SetFrequentUpdates(element, state)
|
||||
--if(not unit or (unit ~= 'player' and unit ~= 'pet')) then return end
|
||||
|
||||
if(element.frequentUpdates ~= state) then
|
||||
element.frequentUpdates = state
|
||||
if(element.frequentUpdates and not element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', onRageUpdate)
|
||||
|
||||
element.__owner:UnregisterEvent('UNIT_RAGE', Path)
|
||||
elseif(not element.frequentUpdates and element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', nil)
|
||||
|
||||
element.__owner:RegisterEvent('UNIT_RAGE', Path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Rage
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
element.SetColorDisconnected = SetColorDisconnected
|
||||
element.SetColorTapping = SetColorTapping
|
||||
element.SetColorThreat = SetColorThreat
|
||||
element.SetColorHappiness = SetColorHappiness
|
||||
element.SetFrequentUpdates = SetFrequentUpdates
|
||||
|
||||
if(element.colorDisconnected) then
|
||||
self:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorTapping) then
|
||||
self:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorThreat) then
|
||||
self:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorHappiness) then
|
||||
self:RegisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
|
||||
-- if(element.frequentUpdates and (unit == 'player' or unit == 'pet')) then
|
||||
if((unit == 'player' or unit == 'pet')) then
|
||||
element:SetScript('OnUpdate', onRageUpdate)
|
||||
else
|
||||
self:RegisterEvent('UNIT_RAGE', Path)
|
||||
end
|
||||
|
||||
self:RegisterEvent('UNIT_MAXRAGE', Path)
|
||||
|
||||
if(element:IsObjectType('StatusBar')) then
|
||||
element.texture = element:GetStatusBarTexture() and element:GetStatusBarTexture():GetTexture() or [[Interface\TargetingFrame\UI-StatusBar]]
|
||||
element:SetStatusBarTexture(element.texture)
|
||||
end
|
||||
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Rage
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
if(element:GetScript('OnUpdate')) then
|
||||
element:SetScript('OnUpdate', nil)
|
||||
else
|
||||
self:UnregisterEvent('UNIT_RAGE', Path)
|
||||
end
|
||||
|
||||
self:UnregisterEvent('UNIT_MAXRAGE', Path)
|
||||
|
||||
self:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
self:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_HAPPINESS', ColorPath)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Rage', Path, Enable, Disable)
|
||||
@@ -0,0 +1,118 @@
|
||||
--[[
|
||||
# Element: PvP Icon
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's PvP status.
|
||||
|
||||
## Widget
|
||||
|
||||
PvPIndicator - A `Texture` used to display faction, FFA PvP status icon.
|
||||
|
||||
## Notes
|
||||
|
||||
This element updates by changing the texture.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local PvPIndicator = self:CreateTexture(nil, 'ARTWORK', nil, 1)
|
||||
PvPIndicator:SetSize(30, 30)
|
||||
PvPIndicator:SetPoint('RIGHT', self, 'LEFT')
|
||||
|
||||
-- Register it with oUF
|
||||
self.PvPIndicator = PvPIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local UnitFactionGroup = UnitFactionGroup
|
||||
local UnitIsPVP = UnitIsPVP
|
||||
local UnitIsPVPFreeForAll = UnitIsPVPFreeForAll
|
||||
|
||||
local FFA_ICON = [[Interface\TargetingFrame\UI-PVP-FFA]]
|
||||
local FACTION_ICON = [[Interface\TargetingFrame\UI-PVP-]]
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(unit ~= self.unit) then return end
|
||||
|
||||
local element = self.PvPIndicator
|
||||
|
||||
--[[ Callback: PvPIndicator:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the PvPIndicator element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local status
|
||||
local factionGroup = UnitFactionGroup(unit)
|
||||
|
||||
if(UnitIsPVPFreeForAll(unit)) then
|
||||
element:SetTexture(FFA_ICON)
|
||||
element:SetTexCoord(0, 0.65625, 0, 0.65625)
|
||||
status = 'ffa'
|
||||
elseif(factionGroup and factionGroup ~= 'Neutral' and UnitIsPVP(unit)) then
|
||||
element:SetTexture(FACTION_ICON .. factionGroup)
|
||||
element:SetTexCoord(0, 0.65625, 0, 0.65625)
|
||||
status = factionGroup
|
||||
end
|
||||
|
||||
if(status) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: PvPIndicator:PostUpdate(unit, status)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the PvPIndicator element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* status - the unit's current PvP status or faction accounting for mercenary mode (string)['ffa', 'Alliance',
|
||||
'Horde']
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, status)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[Override: PvPIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.PvPIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.PvPIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_FACTION', Path)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.PvPIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_FACTION', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('PvPIndicator', Path, Enable, Disable)
|
||||
@@ -0,0 +1,115 @@
|
||||
--[[
|
||||
# Element: Raid Role Indicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's raid assignment (main tank or main assist).
|
||||
|
||||
## Widget
|
||||
|
||||
RaidRoleIndicator - A `Texture` representing the unit's raid assignment.
|
||||
|
||||
## Notes
|
||||
|
||||
This element updates by changing the texture.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local RaidRoleIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
RaidRoleIndicator:SetSize(16, 16)
|
||||
RaidRoleIndicator:SetPoint('TOPLEFT')
|
||||
|
||||
-- Register it with oUF
|
||||
self.RaidRoleIndicator = RaidRoleIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local GetPartyAssignment = GetPartyAssignment
|
||||
local UnitHasVehicleUI = UnitHasVehicleUI
|
||||
local UnitInRaid = UnitInRaid
|
||||
|
||||
local MAINTANK_ICON = [[Interface\GROUPFRAME\UI-GROUP-MAINTANKICON]]
|
||||
local MAINASSIST_ICON = [[Interface\GROUPFRAME\UI-GROUP-MAINASSISTICON]]
|
||||
|
||||
local function Update(self, event)
|
||||
local unit = self.unit
|
||||
|
||||
local element = self.RaidRoleIndicator
|
||||
|
||||
--[[ Callback: RaidRoleIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the RaidRoleIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local role, isShown
|
||||
if(UnitInRaid(unit) and not UnitHasVehicleUI(unit)) then
|
||||
if(GetPartyAssignment('MAINTANK', unit)) then
|
||||
isShown = true
|
||||
element:SetTexture(MAINTANK_ICON)
|
||||
role = 'MAINTANK'
|
||||
elseif(GetPartyAssignment('MAINASSIST', unit)) then
|
||||
isShown = true
|
||||
element:SetTexture(MAINASSIST_ICON)
|
||||
role = 'MAINASSIST'
|
||||
end
|
||||
end
|
||||
|
||||
if isShown then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: RaidRoleIndicator:PostUpdate(role)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the RaidRoleIndicator element
|
||||
* role - the unit's raid assignment (string?)['MAINTANK', 'MAINASSIST']
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(role)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: RaidRoleIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.RaidRoleIndicator.Override or Update)(self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.RaidRoleIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('PARTY_MEMBERS_CHANGED', Path, true)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.RaidRoleIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('PARTY_MEMBERS_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('RaidRoleIndicator', Path, Enable, Disable)
|
||||
@@ -0,0 +1,102 @@
|
||||
--[[
|
||||
# Element: Raid Target Indicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's raid target assignment.
|
||||
|
||||
## Widget
|
||||
|
||||
RaidTargetIndicator - A `Texture` used to display the raid target icon.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local RaidTargetIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
RaidTargetIndicator:SetSize(16, 16)
|
||||
RaidTargetIndicator:SetPoint('TOPRIGHT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.RaidTargetIndicator = RaidTargetIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local GetRaidTargetIndex = GetRaidTargetIndex
|
||||
local SetRaidTargetIconTexture = SetRaidTargetIconTexture
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.RaidTargetIndicator
|
||||
|
||||
--[[ Callback: RaidTargetIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the RaidTargetIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local index = GetRaidTargetIndex(self.unit)
|
||||
if(index) then
|
||||
SetRaidTargetIconTexture(element, index)
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: RaidTargetIndicator:PostUpdate(index)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the RaidTargetIndicator element
|
||||
* index - the index of the raid target marker (number?)[1-8]
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(index)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: RaidTargetIndicator.Override(self, event)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
return (self.RaidTargetIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
if(not element.__owner.unit) then return end
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.RaidTargetIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('RAID_TARGET_UPDATE', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\TargetingFrame\UI-RaidTargetingIcons]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.RaidTargetIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('RAID_TARGET_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('RaidTargetIndicator', Path, Enable, Disable)
|
||||
@@ -0,0 +1,137 @@
|
||||
--[[
|
||||
# Element: Range Fader
|
||||
|
||||
Changes the opacity of a unit frame based on whether the frame's unit is in the player's range.
|
||||
|
||||
## Widget
|
||||
|
||||
Range - A table containing opacity values.
|
||||
|
||||
## Notes
|
||||
|
||||
Offline units are handled as if they are in range.
|
||||
|
||||
## Options
|
||||
|
||||
.outsideAlpha - Opacity when the unit is out of range. Defaults to 0.55 (number)[0-1].
|
||||
.insideAlpha - Opacity when the unit is within range. Defaults to 1 (number)[0-1].
|
||||
|
||||
## Examples
|
||||
|
||||
-- Register with oUF
|
||||
self.Range = {
|
||||
insideAlpha = 1,
|
||||
outsideAlpha = 1/2,
|
||||
}
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local _FRAMES = {}
|
||||
local OnRangeFrame
|
||||
|
||||
local UnitInRange, UnitIsConnected = UnitInRange, UnitIsConnected
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.Range
|
||||
local unit = self.unit
|
||||
|
||||
--[[ Callback: Range:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Range element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local inRange
|
||||
local connected = UnitIsConnected(unit)
|
||||
if(connected) then
|
||||
inRange = UnitInRange(unit)
|
||||
if(not inRange) then
|
||||
self:SetAlpha(element.outsideAlpha)
|
||||
else
|
||||
self:SetAlpha(element.insideAlpha)
|
||||
end
|
||||
else
|
||||
self:SetAlpha(element.insideAlpha)
|
||||
end
|
||||
|
||||
--[[ Callback: Range:PostUpdate(object, inRange, isConnected)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Range element
|
||||
* object - the parent object
|
||||
* inRange - indicates if the unit was within 40 yards of the player (boolean)
|
||||
* isConnected - indicates if the unit is online (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(self, inRange, connected)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Range.Override(self, event)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
return (self.Range.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
-- Internal updating method
|
||||
local timer = 0
|
||||
local function OnRangeUpdate(_, elapsed)
|
||||
timer = timer + elapsed
|
||||
|
||||
if(timer >= .20) then
|
||||
for _, object in next, _FRAMES do
|
||||
if(object:IsShown()) then
|
||||
Path(object, 'OnUpdate')
|
||||
end
|
||||
end
|
||||
|
||||
timer = 0
|
||||
end
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.Range
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.insideAlpha = element.insideAlpha or 1
|
||||
element.outsideAlpha = element.outsideAlpha or 0.55
|
||||
|
||||
if(not OnRangeFrame) then
|
||||
OnRangeFrame = CreateFrame('Frame')
|
||||
OnRangeFrame:SetScript('OnUpdate', OnRangeUpdate)
|
||||
end
|
||||
|
||||
table.insert(_FRAMES, self)
|
||||
OnRangeFrame:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Range
|
||||
if(element) then
|
||||
for index, frame in next, _FRAMES do
|
||||
if(frame == self) then
|
||||
table.remove(_FRAMES, index)
|
||||
break
|
||||
end
|
||||
end
|
||||
self:SetAlpha(element.insideAlpha)
|
||||
|
||||
if(#_FRAMES == 0) then
|
||||
OnRangeFrame:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Range', nil, Enable, Disable)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user