-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathPrint.lua
94 lines (76 loc) · 2.26 KB
/
Print.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
--[[----------------------------------------------------------------------------
LiteMount/Print.lua
AddMessage() into the currently displayed chat window.
Copyright 2011 Mike Battersby
----------------------------------------------------------------------------]]--
local _, LM = ...
local debugLines = {}
local debugLinePos = 1
local maxDebugLines = 100
local format = format
function LM.Print(...)
local msg = format(...)
local f = SELECTED_CHAT_FRAME or DEFAULT_CHAT_FRAME
f:AddMessage("|cff00ff00LiteMount:|r " .. msg)
end
function LM.PrintError(...)
local msg = format(...)
LM.Print("|cffff6666" .. msg .. "|r")
end
function LM.GetDebugLines()
local out = {}
for i = 1, maxDebugLines do
local offset = (debugLinePos + i - 1) % (maxDebugLines + 1)
if debugLines[offset] then
out[#out+1] = debugLines[offset]
end
end
return out
end
function LM.Debug(...)
local msg = format(...)
debugLines[debugLinePos] = msg
debugLinePos = ( debugLinePos + 1 ) % (maxDebugLines + 1)
if LM.Options:GetOption('debugEnabled') then
LM.Print(msg)
end
end
local function GetFrameNameInternal(frame)
local name = frame:GetName()
if name then
if name:sub(1,9) == "LiteMount" then
return name:sub(10)
else
return name
end
end
local parent = frame:GetParent()
for childName, child in pairs(parent) do
if child == frame then
return GetFrameNameInternal(parent)..'.'..childName
end
end
name = tostring(frame):sub(10)
return GetFrameNameInternal(parent)..'.'..name
end
local function GetFrameName(frame)
if not frame.__printableName then
frame.__printableName = GetFrameNameInternal(frame)
end
return frame.__printableName
end
function LM.UIDebug(frame, ...)
local msg = format(...)
if LM.Options:GetOption('uiDebugEnabled') then
local name = GetFrameName(frame)
LM.Print(ORANGE_FONT_COLOR:WrapTextInColorCode(name) .. ' : ' .. msg)
end
end
-- This prints into the UI error box the same as Blizzards code
function LM.Warning(msg)
UIErrorsFrame:AddMessage(msg, 1.0, 0.1, 0.1)
end
function LM.WarningAndPrint(...)
LM.Warning(...)
LM.PrintError(...)
end