vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 local setpoints = {};
3  
4 if (not Nurfed_Utility) then
5  
6 Nurfed_Utility = {};
7 Nurfed_Utility.hooks = {};
8  
9 function Nurfed_Utility:New()
10 local object = {};
11 setmetatable(object, self);
12 self.__index = self;
13 return object;
14 end
15  
16 function Nurfed_Utility:Print(msg, out, r, g, b, a)
17 if (not msg) then return; end
18 if (not out) then out = 1; end
19 if (not r) then r = 1.0; end
20 if (not g) then g = 1.0; end
21 if (not b) then b = 1.0; end
22 if (not a) then a = 1.0; end
23  
24 if (type(out) ~= "number") then
25 UIErrorsFrame:AddMessage(msg, r, g, b, a, UIERRORS_HOLD_TIME);
26 else
27 local frame = getglobal("ChatFrame"..out);
28 if (frame) then
29 frame:AddMessage(msg, r, g, b);
30 else
31 DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b);
32 end
33 end
34 end
35  
36 function Nurfed_Utility:TableCopy(t)
37 local new = {};
38 local i, v = next(t, nil);
39 while i do
40 if type(v)=="table" then
41 v=self:TableCopy(v);
42 end
43 new[i] = v;
44 i, v = next(t, i);
45 end
46 return new;
47 end
48  
49 function Nurfed_Utility:GetTableIndex(tablename, text)
50 for i = 1, table.getn(tablename) do
51 if (tablename[i].text == text) then
52 return i;
53 end
54 end
55 return nil;
56 end
57  
58 function Nurfed_Utility:FormatGS(globalString, anchor)
59 globalString = string.gsub(globalString, "%.", "%%.");
60 globalString = string.gsub(globalString, "%(", "%%(");
61 globalString = string.gsub(globalString, "%)", "%%)");
62 globalString = string.gsub(globalString, "%%[1234567890$]*s", "(.+)");
63 globalString = string.gsub(globalString, "%%[1234567890$]*d", "(%%d+)");
64 if (anchor) then
65 return "^"..globalString;
66 end
67 return globalString;
68 end
69  
70 -- Respect to GypsyMod for the Hook Code
71 function Nurfed_Utility:Hook (mode, original, new)
72 if (not self.hooks[original]) then
73 self.hooks[original] = getglobal(original);
74 if (mode == "before") then
75 setglobal(original, function (...)
76 new(unpack(arg));
77 self.hooks[original](unpack(arg));
78 end);
79 elseif (mode == "after") then
80 setglobal(original, function (...)
81 self.hooks[original](unpack(arg));
82 new(unpack(arg));
83 end);
84 elseif (mode == "replace") then
85 setglobal(original, function (...)
86 new(unpack(arg));
87 end);
88 end
89 end
90 end
91  
92 function Nurfed_Utility:UnHook (original)
93 if (self.hooks[original]) then
94 setglobal(original, self.hooks[original]);
95 self.hooks[original] = nil;
96 end
97 end
98  
99 function Nurfed_Utility:FormatBinding(text)
100 text = string.gsub(text, "CTRL%-", "C-");
101 text = string.gsub(text, "ALT%-", "A-");
102 text = string.gsub(text, "SHIFT%-", "S-");
103 text = string.gsub(text, "Num Pad", "NP");
104 text = string.gsub(text, "Backspace", "Bksp");
105 text = string.gsub(text, "Spacebar", "Space");
106 text = string.gsub(text, "Page", "Pg");
107 text = string.gsub(text, "Down", "Dn");
108 text = string.gsub(text, "Arrow", "");
109 text = string.gsub(text, "Insert", "Ins");
110 text = string.gsub(text, "Delete", "Del");
111 return text;
112 end
113  
114 function Nurfed_Utility:OffScreen(frame)
115 if (not frame or not frame:IsVisible()) then
116 return;
117 end
118 local offscreenX, offscreenY;
119  
120 if (frame:GetLeft() * frame:GetEffectiveScale() < UIParent:GetLeft() * UIParent:GetEffectiveScale()) then
121 offscreenX = -1;
122 elseif (frame:GetRight() * frame:GetEffectiveScale() > UIParent:GetRight() * UIParent:GetEffectiveScale()) then
123 offscreenX = 1;
124 else
125 offscreenX = 0;
126 end
127  
128 if (frame:GetTop() * frame:GetEffectiveScale() > UIParent:GetTop() * UIParent:GetEffectiveScale()) then
129 offscreenY = -1;
130 elseif (frame:GetBottom() * frame:GetEffectiveScale() < UIParent:GetBottom() * UIParent:GetEffectiveScale()) then
131 offscreenY = 1;
132 else
133 offscreenY = 0;
134 end
135  
136 return offscreenX, offscreenY;
137 end
138 end