-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathhooks.lua
More file actions
142 lines (112 loc) · 4.47 KB
/
Copy pathhooks.lua
File metadata and controls
142 lines (112 loc) · 4.47 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
EngBank_hookfunctions = {
"BagSlotButton_OnClick",
"BagSlotButton_OnDrag",
"CloseAllWindows",
"ToggleDropDownMenu"
};
EngBank_savedhookfunctions = {};
-- reg :
EngBank_HOOKS_UNREGISTER = 0;
EngBank_HOOKS_REGISTER = 1;
EngBank_HOOKS_CHECK = 2;
--
function EngBank_RegisterHooks(reg)
local func, func2;
if (reg == 1) then
for i = 1, table.getn(EngBank_hookfunctions) do
func = getglobal( "EngBank_hook_"..EngBank_hookfunctions[i] );
if (func) then
EngBank_savedhookfunctions[ EngBank_hookfunctions[i] ] = getglobal( EngBank_hookfunctions[i] );
setglobal( EngBank_hookfunctions[i], func);
EngBags_PrintDEBUG("Hook function for '"..EngBank_hookfunctions[i].." installed.");
else
EngBags_PrintDEBUG("** Hook function for '"..EngBank_hookfunctions[i].." SKIPPED **");
end
end
elseif (reg == 0) then
-- unregister hooks
for i = 1, table.getn(EngBank_hookfunctions) do
func = getglobal( "EngBank_hook_"..EngBank_hookfunctions[i] );
if ( (func) and (EngBank_savedhookfunctions[EngBank_hookfunctions[i]]) ) then
setglobal( EngBank_hookfunctions[i], EngBank_savedhookfunctions[EngBank_hookfunctions[i]]);
EngBank_savedhookfunctions[EngBank_hookfunctions[i]] = nil;
EngBags_PrintDEBUG("Hook function for '"..EngBank_hookfunctions[i].." removed.");
end
end
elseif (reg == 2) then
-- check if hooks are registered
EngBags_Print( "EngBank hooks:" ,1,1,0.2 );
for i = 1, table.getn(EngBank_hookfunctions) do
func = getglobal( "EngBank_hook_"..EngBank_hookfunctions[i] );
func2 = getglobal( EngBank_hookfunctions[i] );
if ( func == func2 ) then
EngBags_Print( " "..EngBank_hookfunctions[i].." is hooked properly." ,0,1,0.25 );
else
EngBags_Print( " "..EngBank_hookfunctions[i].." is NOT hooked." ,1,0.2,0.2 );
end
end
end
end
function EngBank_OpenOrClose(opt)
if ( opt == "toggle" ) then
if (EngBank_frame:IsVisible()) then
opt = "close";
else
opt = "open";
end
end
if ( opt == "open" ) then
EngBank_resort_required = EngBank_MANDATORY;
EngBank_edit_mode = 0;
EngBank_frame:Show();
elseif ( opt == "close" ) then
EngBank_frame:Hide();
end
end
function EngBank_hook_BagSlotButton_OnClick()
EngBags_PrintDEBUG("event: BagSlotButton_OnClick()");
EngBank_savedhookfunctions["BagSlotButton_OnClick"]();
EngBank_UpdateWindow();
end
function EngBank_hook_BagSlotButton_OnDrag()
EngBank_savedhookfunctions["BagSlotButton_OnDrag"]();
EngBags_PrintDEBUG("event: BagSlotButton_OnDrag()");
EngBank_UpdateWindow();
end
function EngBank_hook_CloseAllWindows()
EngBags_PrintDEBUG("event: CloseAllWindows()");
local itemsVisible = EngBank_savedhookfunctions["CloseAllWindows"]();
local engVisible = EngBank_frame:IsVisible();
if (engVisible) then
EngBank_OpenOrClose("close");
end
CloseBankFrame();
return (itemsVisible or engVisible);
end
function EngBank_hook_ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yOffset)
EngBags_PrintDEBUG("event: ToggleDropDownMenu()");
EngBank_savedhookfunctions["ToggleDropDownMenu"](level, value, dropDownFrame, anchorName, xOffset, yOffset);
local frame = getglobal("DropDownList"..UIDROPDOWNMENU_MENU_LEVEL);
local adjustX, adjustY;
if ( frame and frame:GetLeft() and frame:GetLeft() * frame:GetScale() < UIParent:GetLeft() * UIParent:GetScale() ) then
adjustX = ( (UIParent:GetLeft()*UIParent:GetScale()) - (frame:GetLeft()*frame:GetScale()) ) / frame:GetScale();
elseif ( frame and frame:GetRight() and frame:GetRight()*frame:GetScale() > UIParent:GetRight()*UIParent:GetScale() ) then
adjustX = ( (UIParent:GetRight()*UIParent:GetScale()) - (frame:GetRight()*frame:GetScale()) ) / frame:GetScale();
else
adjustX = 0;
end
if ( frame and frame:GetTop() and frame:GetTop()*frame:GetScale() > UIParent:GetTop()*UIParent:GetScale() ) then
adjustY = ( (UIParent:GetTop()*UIParent:GetScale()) - (frame:GetTop()*frame:GetScale()) ) / frame:GetScale();
elseif ( frame and frame:GetBottom() and frame:GetBottom() * frame:GetScale() < UIParent:GetBottom() * UIParent:GetScale() ) then
adjustY = ( (UIParent:GetBottom()*UIParent:GetScale()) - (frame:GetBottom()*frame:GetScale()) ) / frame:GetScale();
else
adjustY = 0;
end
if ( (adjustY ~= 0) or (adjustX ~= 0) ) then
EngBags_PrintDEBUG("ToggleDropDownMenu() - adjusting window position by "..adjustX..", "..adjustY);
adjustX = frame:GetLeft() + adjustX;
adjustY = frame:GetTop() + adjustY;
frame:ClearAllPoints();
frame:SetPoint("TOPLEFT", "UIParent", "BOTTOMLEFT", adjustX, adjustY);
end
end