-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutoBarConfigSlot.lua
280 lines (239 loc) · 9.73 KB
/
AutoBarConfigSlot.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
--
-- AutoBarConfigSlot
--
-- Slot Config functions
--
-- Maintained by Azethoth / Toadkiller of Proudmoore.
-- http://www.curse-gaming.com/en/wow/addons-4430-1-autobar-toadkiller.html
--
--
-- Config Checkbox Handling
--
AutoBarConfigSlot = {};
local L = AceLibrary("AceLocale-2.1"):GetInstance("AutoBar", true);
local Compost = AceLibrary("Compost-2.0");
function AutoBarConfigSlot:View(slotsIndex, playerInfo)
AutoBarConfigSlotFrameTitleText:SetText(L["VIEWSLOT"]);
AutoBarConfigSlotFrameViewText:Show();
AutoBarConfigSlot.editable = false;
AutoBarConfigSlot:Initialize(slotsIndex, playerInfo);
AutoBarConfigSlotFrameClearSlotButton:Hide();
AutoBarConfigSlotFrameEmptySlotButton:Hide();
AutoBarConfigSlotFrameNoPopup:Disable();
AutoBarConfigSlotFrameArrangeOnUse:Disable();
AutoBarConfigSlotFrameRightClickTargetsPet:Disable();
AutoBarConfigSlotFrameNoPopupText:SetVertexColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
AutoBarConfigSlotFrameArrangeOnUseText:SetVertexColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
AutoBarConfigSlotFrameRightClickTargetsPetText:SetVertexColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
AutoBarConfigSlotFrame:SetBackdropColor(0.30,0.15,0.15);
end
function AutoBarConfigSlot:Edit(slotsIndex, playerInfo)
AutoBarConfigSlotFrameTitleText:SetText(L["EDITSLOT"].." #" .. slotsIndex);
AutoBarConfigSlotFrameViewText:Hide();
AutoBarConfigSlot.editable = true;
AutoBarConfigSlot:Initialize(slotsIndex, playerInfo);
AutoBarConfigSlotFrameClearSlotButton:Show();
AutoBarConfigSlotFrameEmptySlotButton:Show();
AutoBarConfigSlotFrameNoPopup:Enable();
AutoBarConfigSlotFrameArrangeOnUse:Enable();
AutoBarConfigSlotFrameRightClickTargetsPet:Enable();
AutoBarConfigSlotFrameNoPopupText:SetVertexColor(NORMAL_FONT_COLOR.r , NORMAL_FONT_COLOR.g , NORMAL_FONT_COLOR.b);
AutoBarConfigSlotFrameArrangeOnUseText:SetVertexColor(NORMAL_FONT_COLOR.r , NORMAL_FONT_COLOR.g , NORMAL_FONT_COLOR.b);
AutoBarConfigSlotFrameRightClickTargetsPetText:SetVertexColor(NORMAL_FONT_COLOR.r , NORMAL_FONT_COLOR.g , NORMAL_FONT_COLOR.b);
AutoBarConfigSlotFrame:SetBackdropColor(0.15,0.20,0.15);
end
function AutoBarConfigSlot:Initialize(slotsIndex, playerInfo)
AutoBarConfigSlot.slots = playerInfo.buttons;
AutoBarConfigSlot.slotsIndex = slotsIndex;
getglobal("AutoBarConfigSlotFrameNoPopupText"):SetText(L["AUTOBAR_CONFIG_NOPOPUP"]);
getglobal("AutoBarConfigSlotFrameArrangeOnUseText"):SetText(L["AUTOBAR_CONFIG_ARRANGEONUSE"]);
getglobal("AutoBarConfigSlotFrameRightClickTargetsPetText"):SetText(L["AUTOBAR_CONFIG_RIGHTCLICKTARGETSPET"]);
AutoBarConfigSlot:Update();
AutoBarConfigSlotFrame:Show();
end
function AutoBarConfigSlot:Update()
if (not AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex]) then
AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex] = Compost:GetTable();
end
local buttonInfo = AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex];
local noPopupCheckbox = getglobal("AutoBarConfigSlotFrameNoPopup");
local arrangeOnUseCheckbox = getglobal("AutoBarConfigSlotFrameArrangeOnUse");
local rightClickTargetsPetCheckbox = getglobal("AutoBarConfigSlotFrameRightClickTargetsPet");
local index,tmp,i;
noPopupCheckbox:SetChecked(buttonInfo.noPopup);
arrangeOnUseCheckbox:SetChecked(buttonInfo.arrangeOnUse);
rightClickTargetsPetCheckbox:SetChecked(buttonInfo.rightClickTargetsPet);
tmp = 0;
for index = 1, AUTOBAR_MAXSLOTCATEGORIES, 1 do
if (buttonInfo[index]) then
tmp = index;
end
end
index = 1;
while (index < tmp) do
if (buttonInfo[index]) then
index = index + 1;
else
buttonInfo[index] =
buttonInfo[index+1];
buttonInfo[index+1] = nil;
tmp = 0;
for i = 1, AUTOBAR_MAXSLOTCATEGORIES, 1 do
if (buttonInfo[i]) then
tmp = i;
end
end
end
end
for index = 1, AUTOBAR_MAXSLOTCATEGORIES, 1 do
local button = getglobal("AutoBarConfigSlotFrame_Button"..index);
local hotkey = getglobal("AutoBarConfigSlotFrame_Button"..index.."HotKey");
local count = getglobal("AutoBarConfigSlotFrame_Button"..index.."Count");
local icon = getglobal("AutoBarConfigSlotFrame_Button"..index.."Icon");
local checkbox = getglobal("AutoBarConfigSlotFrame_Option"..index);
local checkboxText = getglobal("AutoBarConfigSlotFrame_Option"..index.."Text");
hotkey:Hide();
if (buttonInfo[index]) then
count:SetText("");
if (AutoBar_Category_Info[buttonInfo[index]] and AutoBar_Category_Info[buttonInfo[index]].targetted) then
checkbox:Show();
checkboxText:SetText(L["AUTOBAR_CONFIG_SMARTSELFCAST"]);
if (AutoBar_Config[AutoBarConfig.editPlayer].smartSelfcast and AutoBar_Config[AutoBarConfig.editPlayer].smartSelfcast[buttonInfo[index]]) then
checkbox:SetChecked(1);
else
checkbox:SetChecked(0);
end
else
checkbox:Hide();
end
else
count:SetText("Empty");
checkbox:Hide();
end
icon:SetTexture(AutoBar_GetTexture(buttonInfo[index]));
button:Show();
end
end
-- Individual smart self cast checkbox handling
function AutoBarConfigSlot:SelfCastCheckboxOnCheck()
local buttonInfo = AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex];
local category;
if (type(buttonInfo) == "table") then
category = buttonInfo[this:GetID()];
else
category = buttonInfo;
end
if (not AutoBar_Config[AutoBarConfig.editPlayer].smartSelfcast) then
AutoBar_Config[AutoBarConfig.editPlayer].smartSelfcast = {};
end
AutoBar_Config[AutoBarConfig.editPlayer].smartSelfcast[category] = this:GetChecked();
AutoBarConfigSlot:Update();
AutoBarProfile:ButtonsChanged();
end
function AutoBarConfigSlot:OnCheck()
local buttonInfo = AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex];
local buttonName = this:GetName();
if (type(buttonInfo) == "table") then
if (buttonName == "AutoBarConfigSlotFrameNoPopup") then
buttonInfo.noPopup = this:GetChecked();
elseif (buttonName == "AutoBarConfigSlotFrameArrangeOnUse") then
buttonInfo.arrangeOnUse = this:GetChecked();
elseif (buttonName == "AutoBarConfigSlotFrameRightClickTargetsPet") then
buttonInfo.rightClickTargetsPet = this:GetChecked();
end
end
AutoBarConfigSlot:Update();
AutoBarProfile:ButtonsChanged();
end
function AutoBarConfigSlot:ButtonOnClick(mousebutton)
ResetCursor();
AutoBar.dragging = nil;
if (not AutoBarConfigSlot.editable) then
return;
end
local dragBag, dragSlot = AutoBarConfig:GetDragBagSlot();
if (CursorHasItem() and dragBag and dragSlot and AutoBarConfigSlot.editable) then
AutoBarConfigSlot.ButtonOnReceiveDrag();
else
local slotInfo = AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex];
local category = nil;
AutoBarChooseCategoryFrame.editting = this:GetID();
if (AutoBarChooseCategoryFrame.editting > table.getn(slotInfo) + 1) then
AutoBarChooseCategoryFrame.editting = table.getn(slotInfo) + 1;
end
category = slotInfo[AutoBarChooseCategoryFrame.editting];
if (not AutoBarConfigSlot.editable) then
AutoBarChooseCategoryFrame.editting = nil;
if (AutoBar_Category_Info[category]) then
AutoBarChooseCategoryFrame.categoryexplore = category;
else
return;
end
end
AutoBarChooseCategoryFrame:Show();
end
end
function AutoBarConfigSlot.ButtonOnDragStart()
local fromIndex = this:GetID();
AutoBar.SetDraggingIndex("AutoBarConfigSlotFrame", fromIndex);
SetCursor("BUY_CURSOR");
end
function AutoBarConfigSlot.ButtonOnReceiveDrag()
local toIndex = this:GetID();
local fromIndex = AutoBar.GetDraggingIndex("AutoBarConfigSlotFrame");
-- DEFAULT_CHAT_FRAME:AddMessage("AutoBarConfig.ButtonOnReceiveDrag " .. tostring(fromIndex) .. " -> " .. toIndex, 1, 0.5, 0);
if (fromIndex and fromIndex ~= toIndex) then
AutoBarConfigSlot:MoveButtonItems(AutoBarConfigSlot.slotsIndex, fromIndex, toIndex);
elseif (CursorHasItem()) then
local dragBag, dragSlot = AutoBarConfig:GetDragBagSlot();
if (dragBag and dragSlot) then
local slotInfo = AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex];
local name, id = AutoBar.LinkDecode(GetContainerItemLink(dragBag, dragSlot));
if (table.getn(slotInfo) < toIndex) then
toIndex = table.getn(slotInfo) + 1;
end
AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex][toIndex] = id;
dragBag = nil;
dragSlot = nil;
ClearCursor();
end
end
AutoBarConfigSlot:Update();
AutoBarProfile:ButtonsChanged();
AutoBar.dragging = nil;
ResetCursor();
end
function AutoBarConfigSlot:MoveButtonItems(button, fromIndex, toIndex)
if (type(AutoBarConfigSlot.slots[button]) == "table") then
if (not AutoBarConfigSlot.slots[button][fromIndex] or fromIndex == toIndex) then
-- Move to self so do nothing
return;
end
if (not AutoBarConfigSlot.slots[button][fromIndex]) then
-- Dont allow swapping empties into the list
return;
end
local temp = AutoBarConfigSlot.slots[button][fromIndex];
if (not AutoBarConfigSlot.slots[button][toIndex]) then
-- Move to the end
table.remove(AutoBarConfigSlot.slots[button], fromIndex);
table.insert(AutoBarConfigSlot.slots[button], temp);
else
-- Swap the two
AutoBarConfigSlot.slots[button][fromIndex] = AutoBarConfigSlot.slots[button][toIndex];
AutoBarConfigSlot.slots[button][toIndex] = temp;
end
end
end
-- Delete all items in a slot.
function AutoBarConfigSlot:EmptySlotButtonOnClick()
Compost:Erase(AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex]);
AutoBarConfigSlot:Update();
AutoBarProfile:ButtonsChanged();
end
-- Delete all items in a slot.
function AutoBarConfigSlot:ClearSlotButtonOnClick()
Compost:Recycle(AutoBarConfigSlot.slots[AutoBarConfigSlot.slotsIndex], "AAACLEAR")
AutoBarConfigSlot:Update();
AutoBarProfile:ButtonsChanged();
end