-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuildBankSearch.lua
712 lines (638 loc) · 23.2 KB
/
GuildBankSearch.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
--[[****************************************************************************
* GuildBankSearch by Saiket, originally by Harros *
* GuildBankSearch.lua - Adds a search filter to the guild bank. *
****************************************************************************]]
local m = {}
local isWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC)
local NS = select( 2, ... );
GuildBankSearch = NS;
local L = NS.L;
-- hacky fix for LoadWith not working in TBC
-- https://github.com/Stanzilla/WoWUIBugs/issues/223
function m:OnLoad()
local MAX_GUILDBANK_SLOTS_PER_TAB = 98;
local NUM_SLOTS_PER_GUILDBANK_GROUP = 14;
NS.Frame = CreateFrame( "Frame", "GuildBankSearchFrame", GuildBankFrame );
NS.Frame.UpdateRate = 0.5;
NS.Frame.NextUpdate = 0;
NS.Frame.NeedUpdate = false;
NS.ToggleButton = CreateFrame( "Button", nil, GuildBankFrame, "UIPanelButtonTemplate" );
NS.Clear = CreateFrame( "Button", nil, NS.Frame, "UIPanelButtonTemplate" );
NS.Name = CreateFrame( "EditBox", "$parentName", NS.Frame, "InputBoxTemplate" );
NS.Text = CreateFrame( "EditBox", "$parentText", NS.Frame, "InputBoxTemplate" );
NS.Quality = CreateFrame( "Frame", "$parentQuality", NS.Frame, "UIDropDownMenuTemplate" );
NS.ItemLevelMin = CreateFrame( "EditBox", "$parentItemLevelMin", NS.Frame, "InputBoxTemplate" );
NS.ItemLevelMax = CreateFrame( "EditBox", "$parentItemLevelMax", NS.Frame, "InputBoxTemplate" );
NS.ReqLevelMin = CreateFrame( "EditBox", "$parentReqLevelMin", NS.Frame, "InputBoxTemplate" );
NS.ReqLevelMax = CreateFrame( "EditBox", "$parentReqLevelMax", NS.Frame, "InputBoxTemplate" );
NS.CategorySection = CreateFrame( "Frame", "$parentCategory", NS.Frame, "OptionsBoxTemplate" );
NS.Type = CreateFrame( "Frame", "$parentType", NS.CategorySection, "UIDropDownMenuTemplate" );
NS.SubType = CreateFrame( "Frame", "$parentSubType", NS.CategorySection, "UIDropDownMenuTemplate" );
NS.Slot = CreateFrame( "Frame", "$parentSlot", NS.CategorySection, "UIDropDownMenuTemplate" );
--- Filter parameter table, where filter is active if any keys exist.
-- Initially false so FilterClear() will update all fields to nil.
local Filter = {
Name = false;
Text = false;
Quality = false;
Type = false;
SubType = false;
Slot = false;
ItemLevelMin = false;
ItemLevelMax = false;
ReqLevelMin = false;
ReqLevelMax = false;
};
NS.Filter = Filter;
NS.Qualities = {};
NS.Types = {};
for Index = 1, Enum.ItemClassMeta.NumValues do
NS.Types[ Index ] = GetItemClassInfo( Index-1 );
end
NS.SubTypes = {};
NS.Slots = {}; -- Sorted list of inventory types that can be searched for
NS.SlotGroups = { -- Categories paired with the inventory types that can match them (can be multiple)
[ "ENCHSLOT_WEAPON" ] = { -- Localized as generic "Weapon"
[ "INVTYPE_2HWEAPON" ] = true;
[ "INVTYPE_HOLDABLE" ] = true;
[ "INVTYPE_SHIELD" ] = true;
[ "INVTYPE_WEAPON" ] = true;
[ "INVTYPE_WEAPONMAINHAND" ] = true;
[ "INVTYPE_WEAPONOFFHAND" ] = true;
};
[ "INVTYPE_AMMO" ] = { [ "INVTYPE_AMMO" ] = true; };
[ "INVTYPE_BAG" ] = {
[ "INVTYPE_BAG" ] = true;
[ "INVTYPE_QUIVER" ] = true;
};
[ "INVTYPE_BODY" ] = { [ "INVTYPE_BODY" ] = true; };
[ "INVTYPE_CHEST" ] = {
[ "INVTYPE_CHEST" ] = true;
[ "INVTYPE_ROBE" ] = true;
};
[ "INVTYPE_CLOAK" ] = { [ "INVTYPE_CLOAK" ] = true; };
[ "INVTYPE_FEET" ] = { [ "INVTYPE_FEET" ] = true; };
[ "INVTYPE_FINGER" ] = { [ "INVTYPE_FINGER" ] = true; };
[ "INVTYPE_HAND" ] = { [ "INVTYPE_HAND" ] = true; };
[ "INVTYPE_HEAD" ] = { [ "INVTYPE_HEAD" ] = true; };
[ "INVTYPE_LEGS" ] = { [ "INVTYPE_LEGS" ] = true; };
[ "INVTYPE_NECK" ] = { [ "INVTYPE_NECK" ] = true; };
[ "INVTYPE_RANGED" ] = {
[ "INVTYPE_RANGED" ] = true;
[ "INVTYPE_RANGEDRIGHT" ] = true;
[ "INVTYPE_THROWN" ] = true;
};
[ "INVTYPE_RELIC" ] = { [ "INVTYPE_RELIC" ] = true; };
[ "INVTYPE_SHOULDER" ] = { [ "INVTYPE_SHOULDER" ] = true; };
[ "INVTYPE_TABARD" ] = { [ "INVTYPE_TABARD" ] = true; };
[ "INVTYPE_TRINKET" ] = { [ "INVTYPE_TRINKET" ] = true; };
[ "INVTYPE_WAIST" ] = { [ "INVTYPE_WAIST" ] = true; };
[ "INVTYPE_WRIST" ] = { [ "INVTYPE_WRIST" ] = true; };
};
NS.ButtonMismatchAlpha = 0.25;
NS.LogMismatchColor = { r = 0.25; g = 0.25; b = 0.25; };
NS.Buttons, NS.Tabs = {}, {}; -- Cache of all item and tab buttons in bank view
--- Updates filter when name parameter changes.
function NS.Name:OnTextChanged ()
local Text = self:GetText();
Filter.Name = Text ~= "" and Text:lower() or nil;
NS.FilterUpdate();
end
--- Updates filter when text parameter changes.
function NS.Text:OnTextChanged ()
local Text = self:GetText();
Filter.Text = Text ~= "" and Text:lower() or nil;
NS.FilterUpdate();
end
--- @return An iterator to list all qualities.
function NS.Quality.IterateOptions ()
return ipairs( NS.Qualities );
end
--- Updates the subtype dropdown when a type is chosen.
function NS.Type:OnSelect ( Dropdown, Type )
if ( Filter.Type ~= Type ) then
NS.SubType.OnSelect( nil, NS.SubType ); -- Remove subtype filter
if ( not Type ) then
UIDropDownMenu_DisableDropDown( NS.SubType );
else
UIDropDownMenu_EnableDropDown( NS.SubType );
end
NS.DropdownOnSelect( self, Dropdown, Type );
end
end
--- @return An iterator to list all types.
function NS.Type.IterateOptions ()
local Index = 0;
return function ()
Index = Index + 1;
local Label = NS.Types[ Index ];
return Label, Label;
end;
end
--- @return An iterator to list all sub-types.
function NS.SubType.IterateOptions ()
local Index = 0;
return function ()
Index = Index + 1;
local Label = NS.SubTypes[ Filter.Type ][ Index ];
return Label, Label;
end;
end
--- @return An iterator to list all gear slots.
function NS.Slot.IterateOptions ()
local Index = 0;
return function ()
Index = Index + 1;
local Slot = NS.Slots[ Index ];
return Slot, _G[ Slot ];
end;
end
--- Generic handler to update the filter when one of the level edit boxes changes.
function NS:LevelEditBoxOnTextChanged ()
local NewLevel = self:GetText() ~= "" and self:GetNumber() or nil;
if ( NewLevel ~= Filter[ self.Parameter ] ) then
Filter[ self.Parameter ] = NewLevel;
NS.FilterUpdate();
end
end
--- Generic handler to update the filter when a dropdown's value changes.
function NS:DropdownOnSelect ( Dropdown, Value )
if ( Value ~= Filter[ Dropdown.Parameter ] ) then
UIDropDownMenu_SetText( Dropdown, self and self.value or L.ALL );
Filter[ Dropdown.Parameter ] = Value;
NS.FilterUpdate();
end
end
--- Generic handler to construct dropdown menus using their custom iterators.
function NS:DropdownInitialize ()
local CurrentValue = Filter[ self.Parameter ];
local Info = UIDropDownMenu_CreateInfo();
Info.arg1 = self; -- Arg2 left nil for unfiltered
Info.text = L.ALL;
Info.checked = CurrentValue == nil;
Info.func = self.OnSelect;
UIDropDownMenu_AddButton( Info );
for Value, Label in self.IterateOptions() do
Info.arg2, Info.text = Value, Label;
Info.checked = CurrentValue == Value;
UIDropDownMenu_AddButton( Info );
end
end
--- Resets all filter parameters to not filter anything.
function NS.FilterClear ()
CloseDropDownMenus(); -- Close dropdown if open
NS.Name:SetText( "" );
NS.Text:SetText( "" );
NS.Quality.OnSelect( nil, NS.Quality );
NS.ItemLevelMin:SetText( "" );
NS.ItemLevelMax:SetText( "" );
NS.ReqLevelMin:SetText( "" );
NS.ReqLevelMax:SetText( "" );
-- Item category fields
NS.Type.OnSelect( nil, NS.Type ); -- Also clears SubType
NS.Slot.OnSelect( nil, NS.Slot );
end
--- Requests an update to the bank or log display.
-- @param Force Executes the update on the next frame, ignoring throttling.
function NS.FilterUpdate ( Force )
NS.Frame.NeedUpdate = true;
if ( Force ) then
NS.Frame.NextUpdate = 0;
end
end
--- @return True if any filter parameters are set.
function NS.IsFilterDefined ()
return next( Filter ) ~= nil;
end
do
local Tooltip = CreateFrame( "GameTooltip", "$parentTooltip", NS.Frame );
-- Add template text lines
Tooltip:AddFontStrings( Tooltip:CreateFontString(), Tooltip:CreateFontString() );
local LinesLeft, LinesRight = {}, {};
local select = select;
local FilterFunctions = {
--- Case-insensitive plain text filter by item name.
Name = function ( NamePattern, Name )
return Name:lower():find( NamePattern, 1, true );
end;
--- Case-insensitive plain text filter by tooltip contents.
Text = function ( TextPattern, _, ItemLink )
Tooltip:SetOwner( NS.Frame, "ANCHOR_NONE" );
Tooltip:SetHyperlink( ItemLink );
if ( Tooltip:IsShown() ) then
local NumLines = Tooltip:NumLines();
-- Cache newly created lines
for Line = #LinesLeft + 1, NumLines do
LinesLeft[ Line ] = _G[ Tooltip:GetName().."TextLeft"..Line ];
LinesRight[ Line ] = _G[ Tooltip:GetName().."TextRight"..Line ];
end
-- Search text on visible lines
for Line = 2, NumLines do -- Skip name (first line)
if ( LinesLeft[ Line ]:GetText():lower():find( TextPattern, 1, true )
or ( LinesRight[ Line ]:IsShown()
and LinesRight[ Line ]:GetText():lower():find( TextPattern, 1, true )
) ) then
return true;
end
end
end
end;
--- Filter by item quality.
Quality = function ( QualityFilter, _, _, Quality )
return QualityFilter == Quality;
end;
--- Filter by item type.
Type = function ( TypeFilter, ... )
return TypeFilter == select( 6, ... );
end;
--- Filter by item sub-type.
SubType = function ( SubTypeFilter, ... )
return SubTypeFilter == select( 7, ... );
end;
--- Filter by item gear slot.
Slot = function ( SlotGroup, ... )
return NS.SlotGroups[ SlotGroup ][ select( 9, ... ) ];
end;
--- Filter by item iLvl lower boundary.
ItemLevelMin = function ( Min, _, _, _, ItemLevel )
return ItemLevel >= Min;
end;
--- Filter by item iLvl upper boundary.
ItemLevelMax = function ( Max, _, _, _, ItemLevel )
return ItemLevel <= Max;
end;
--- Filter by item required level lower boundary.
ReqLevelMin = function ( Min, _, _, _, _, ReqLevel )
return ReqLevel >= Min;
end;
--- Filter by item required level upper boundary.
ReqLevelMax = function ( Max, _, _, _, _, ReqLevel )
return ReqLevel <= Max;
end;
};
local pairs = pairs;
--- @return True if item info matches all filter parameters.
local function MatchItemInfo ( ... )
for Key, Value in pairs( Filter ) do
if ( not FilterFunctions[ Key ]( Value, ... ) ) then
return;
end
end
return true; -- Matched all filters
end
local GetItemInfo = GetItemInfo;
--- Tests an item against the current filter parameters.
-- @param ItemLink Link of item to test.
-- @return True if the given ItemLink matches all filter parameters.
function NS.MatchItem ( ItemLink )
if ( ItemLink ) then
return MatchItemInfo( GetItemInfo( ItemLink ) );
end
end
--- @return True if the name matches the player Name filter parameters.
local function MatchPlayerInfo ( ... )
if ( not FilterFunctions.Name( Filter.Name, ... ) ) then
return;
end
return true; -- Matched all filters
end
--- Tests a name against the Name filter parameters.
-- @param PlayerName name of a player.
-- @return True if the given ItemLink matches all filter parameters.
function NS.MatchPlayer ( PlayerName )
if ( PlayerName ) then
return MatchPlayerInfo( PlayerName );
end
end
end
--- Restores an unfiltered view of the bank and log.
function NS.FilterSuspend ()
for _, Tab in ipairs( NS.Tabs ) do
Tab:SetAlpha( 1 );
end
for _, Button in ipairs( NS.Buttons ) do
Button:SetAlpha( 1 );
end
if ( GuildBankFrame.mode == "log" ) then
GuildBankFrame_UpdateLog();
end
end
do
local GetGuildBankItemLink = GetGuildBankItemLink;
--- @return True if Tab contains at least one matching item.
local function MatchTab ( Tab )
for Slot = 1, MAX_GUILDBANK_SLOTS_PER_TAB do
if ( NS.MatchItem( GetGuildBankItemLink( Tab, Slot ) ) ) then
return true;
end
end
end
--- Applies or refreshes the current filter to the bank or log view.
function NS.FilterResume ()
if ( not NS.IsFilterDefined() ) then
return NS.FilterSuspend();
end
local TabCount = GetNumGuildBankTabs();
for Tab = 1, TabCount do
NS.Tabs[ Tab ]:SetAlpha( MatchTab( Tab ) and 1 or NS.ButtonMismatchAlpha );
end
for Tab = TabCount + 1, #NS.Tabs do
NS.Tabs[ Tab ]:SetAlpha( 1 );
end
if ( GuildBankFrame.mode == "bank" ) then
local Tab = GetCurrentGuildBankTab();
if ( Tab <= TabCount ) then
for Slot, Button in ipairs( NS.Buttons ) do
Button:SetAlpha( NS.MatchItem( GetGuildBankItemLink( Tab, Slot ) )
and 1 or NS.ButtonMismatchAlpha );
end
end
elseif ( GuildBankFrame.mode == "log" ) then
GuildBankFrame_UpdateLog();
end
end
end
--- Hook to enable the filter depending on which bank view is displayed.
function NS.GuildBankFrameTabOnClick ()
if ( GuildBankFrame.mode == "log" or GuildBankFrame.mode == "bank" ) then
NS.ToggleButton:Enable();
else
NS.Frame:Hide();
NS.ToggleButton:Disable();
end
end
--- Hook to update the filter display when the bank view type changes.
function NS.GuildBankFrameUpdate ()
NS.FilterUpdate( true );
end
do
local AddMessageBackup = GuildBankMessageFrame.AddMessage;
--- Hook that modifies added messages when a filter is active.
function NS:GuildBankMessageFrameAddMessage ( Message, ... )
if ( GuildBankFrame.mode == "log"
and NS.Frame:IsShown() and NS.IsFilterDefined()
and not NS.MatchItem( Message:match( "|H(item:[^|]+)|h" ) )
and not NS.MatchPlayer( Message:match( "^|c%x%x%x%x%x%x%x%x(.-)|r" ) )
) then
local Color = NS.LogMismatchColor;
-- Remove all color codes
return AddMessageBackup( self,
Message:gsub( "|c%x%x%x%x%x%x%x%x", "" ):gsub( "|r", "" ),
Color.r, Color.g, Color.b, select( 4, ... ) );
end
return AddMessageBackup( self, Message, ... );
end
end
do
local InsertLinkBackup = ChatEdit_InsertLink;
--- Hook to add linked items to the name filter edit box.
function NS.ChatEditInsertLink ( Link, ... )
if ( InsertLinkBackup( Link, ... ) ) then
return true;
elseif ( Link and NS.Name:IsVisible() ) then
local Name = GetItemInfo( Link );
if ( Name ) then
NS.Name:SetText( Name );
return true;
end
end
return false;
end
end
--- Makes room for the filter pane and refreshes the filter when shown.
function NS.Frame:OnShow ()
PlaySound( SOUNDKIT.IG_CHARACTER_INFO_OPEN );
NS.ToggleButton:SetButtonState( "PUSHED", true );
GuildBankTab1:ClearAllPoints();
GuildBankTab1:SetPoint( "TOPLEFT", NS.Frame, "TOPRIGHT", -8, -2 );
-- Query contents of all bank tabs for tab button filtering
for Tab = 1, GetNumGuildBankTabs() do
local _, _, canView = GetGuildBankTabInfo( Tab );
if canView then
QueryGuildBankTab( Tab );
end
end
NS.FilterUpdate( true );
end
--- Undoes changes to bank window and clears any filter display when hidden.
function NS.Frame:OnHide ()
PlaySound( SOUNDKIT.IG_CHARACTER_INFO_CLOSE );
NS.ToggleButton:SetButtonState( "NORMAL" );
GuildBankTab1:ClearAllPoints();
GuildBankTab1:SetPoint( "TOPLEFT", GuildBankFrame, "TOPRIGHT", -1, -32 );
NS.FilterSuspend();
end
--- Throttles filter display updates.
function NS.Frame:OnUpdate ( Elapsed )
self.NextUpdate = self.NextUpdate - Elapsed;
if ( self.NeedUpdate and self.NextUpdate <= 0 ) then
self.NeedUpdate, self.NextUpdate = false, self.UpdateRate;
NS.FilterResume();
end
end
--- Forces a display update when bank contents change.
function NS.Frame:OnEvent ()
NS.FilterUpdate( true );
end
--- Shows or hides the filter pane.
function NS.Toggle ()
NS.Frame:SetShown( not NS.Frame:IsShown() );
end
-- Fill in quality labels
for Index = 0, #ITEM_QUALITY_COLORS do
NS.Qualities[ Index ] = ITEM_QUALITY_COLORS[ Index ].hex
.._G[ "ITEM_QUALITY"..Index.."_DESC" ]..FONT_COLOR_CODE_CLOSE;
end
-- Fill in and sort subtypes
for Index, Type in ipairs( NS.Types ) do
NS.SubTypes[ Type ] = { };
if isWrath then
for SubIndex, SubValue in ipairs({ GetAuctionItemSubClasses( Index-1 ) }) do
NS.SubTypes[ Type ] [ SubIndex ] = GetItemSubClassInfo( Index-1, SubValue );
end
else
for SubIndex, SubValue in ipairs( C_AuctionHouse.GetAuctionItemSubClasses( Index-1 ) ) do
NS.SubTypes[ Type ] [ SubIndex ] = GetItemSubClassInfo( Index-1, SubValue );
end
end
sort( NS.SubTypes[ Type ] );
end
-- Sort types
sort( NS.Types ); -- Note: Use after subtypes are populated so indices don't get mixed up
-- Fill in and sort slots table
for InvType in pairs( NS.SlotGroups ) do
tinsert( NS.Slots, InvType );
end
sort( NS.Slots, function ( Type1, Type2 )
return _G[ Type1 ] < _G[ Type2 ];
end );
-- Cache all item buttons
for Index = 1, MAX_GUILDBANK_SLOTS_PER_TAB do
local Column = floor( ( Index - 1 ) / NUM_SLOTS_PER_GUILDBANK_GROUP ) + 1;
local Slot = ( Index - 1 ) % NUM_SLOTS_PER_GUILDBANK_GROUP + 1;
local Button = GuildBankFrame["Column"..Column]["Button"..Slot];
NS.Buttons[ Index ] = Button;
Button.searchOverlay:SetTexture();
end
-- Remove default UI's search functionality
if not isWrath then
GuildItemSearchBox:Hide();
end
GuildBankFrame:UnregisterEvent( "INVENTORY_SEARCH_UPDATE" );
for Index = 1, MAX_GUILDBANK_TABS do
local Tab = _G[ "GuildBankTab"..Index].Button;
NS.Tabs[ Index ] = Tab;
Tab:UnregisterEvent( "INVENTORY_SEARCH_UPDATE" );
Tab.SearchOverlay:SetTexture();
end
-- Set up filter button
NS.ToggleButton:SetSize( 100, 21 );
if isWrath then
NS.ToggleButton:SetPoint( "TOPRIGHT", -17, -40 );
else
NS.ToggleButton:SetPoint( "TOPRIGHT", -11, -30 );
end
NS.ToggleButton:SetText( L.FILTER );
NS.ToggleButton:SetScript( "OnClick", NS.Toggle );
-- Set up filter pane
local Frame = NS.Frame;
Frame:Hide();
Frame:SetSize( 187, 409 );
Frame:SetPoint( "TOPLEFT", GuildBankFrame, "TOPRIGHT", -2, -18 );
Frame:EnableMouse( true );
Frame:SetToplevel( true );
Frame:SetScript( "OnShow", Frame.OnShow );
Frame:SetScript( "OnHide", Frame.OnHide );
Frame:SetScript( "OnUpdate", Frame.OnUpdate );
Frame:SetScript( "OnEvent", Frame.OnEvent );
Frame:RegisterEvent( "GUILDBANKBAGSLOTS_CHANGED" );
Frame:RegisterEvent( "GUILDBANKLOG_UPDATE" );
-- Artwork
local Label = Frame:CreateFontString( nil, "ARTWORK", "GameFontNormal" );
Label:SetPoint( "TOPLEFT", 4, -10 );
Label:SetText( L.TITLE );
local Top = Frame:CreateTexture( nil, "BACKGROUND" );
Top:SetTexture( [[Interface\AuctionFrame\AuctionHouseDressUpFrame-Top]] );
Top:SetSize( 256, 276 );
Top:SetPoint( "TOPLEFT" );
local Bottom = Frame:CreateTexture( nil, "BACKGROUND" );
Bottom:SetTexture( [[Interface\AuctionFrame\AuctionHouseDressUpFrame-Bottom]] );
Bottom:SetSize( 256, 256 );
Bottom:SetPoint( "TOPLEFT", Top, "BOTTOMLEFT" );
local Corner = Frame:CreateTexture( nil, "BACKGROUND" );
Corner:SetTexture( [[Interface\AuctionFrame\AuctionHouseDressUpFrame-Corner]] );
Corner:SetSize( 32, 32 );
Corner:SetPoint( "TOPRIGHT", -5, -7 );
-- Close button
CreateFrame( "Button", nil, Frame, "UIPanelCloseButton" ):SetPoint( "TOPRIGHT", Corner, 6, 5 );
local Clear = NS.Clear;
Clear:SetSize( 45, 18 );
Clear:SetPoint( "TOPRIGHT", -31, -8 );
Clear:SetText( L.CLEAR );
Clear:SetScript( "OnClick", NS.FilterClear );
-- Filter controls
--- Sets up a dropdown filter control.
-- @param Parameter Key in the Filter table.
local function InitializeDropdown ( self, Parameter, Label )
self:SetPoint( "LEFT", -8, 0 );
self:SetPoint( "RIGHT", -8, 0 );
_G[ self:GetName().."Middle" ]:SetPoint( "RIGHT", -16, 0 );
UIDropDownMenu_JustifyText( self, "LEFT" );
if ( not self.OnSelect ) then
self.OnSelect = NS.DropdownOnSelect;
end
self.initialize = NS.DropdownInitialize;
self.Parameter = Parameter;
self.Label = self:CreateFontString( nil, "OVERLAY", "GameFontHighlightSmall" );
self.Label:SetText( Label );
self.Label:SetPoint( "BOTTOMLEFT", self, "TOPLEFT", 24, 0 );
return self;
end
--- Sets up a numeric editbox as a level filter control.
-- @param Parameter Key in the Filter table.
local function InitializeLevelEditBox ( self, Parameter, Label )
self:SetSize( 25, 16 );
self:SetNumeric( true );
self:SetMaxLetters( 3 );
self:SetAutoFocus( false );
self:SetScript( "OnTextChanged", NS.LevelEditBoxOnTextChanged );
self.Parameter = Parameter;
self.Label = self:CreateFontString( nil, "OVERLAY", "GameFontHighlightSmall" );
self.Label:SetText( Label );
return self;
end
local Name = NS.Name;
Name:SetHeight( 16 );
Name:SetAutoFocus( false );
Name:SetPoint( "TOP", Clear, "BOTTOM", 0, -20 );
Name:SetPoint( "LEFT", 16, 0 );
Name:SetPoint( "RIGHT", -16, 0 );
Name:SetScript( "OnTextChanged", Name.OnTextChanged );
local Label = Name:CreateFontString( nil, "OVERLAY", "GameFontHighlightSmall" );
Label:SetPoint( "BOTTOMLEFT", Name, "TOPLEFT", 1, 0 );
Label:SetText( L.NAME );
local Text = NS.Text;
Text:SetHeight( 16 );
Text:SetAutoFocus( false );
Text:SetPoint( "TOP", Name, "BOTTOM", 0, -12 );
Text:SetPoint( "LEFT", Name );
Text:SetPoint( "RIGHT", Name );
Text:SetScript( "OnTextChanged", Text.OnTextChanged );
local Label = Text:CreateFontString( nil, "OVERLAY", "GameFontHighlightSmall" );
Label:SetPoint( "BOTTOMLEFT", Text, "TOPLEFT", 1, 0 );
Label:SetText( L.TEXT );
InitializeDropdown( NS.Quality, "Quality", L.QUALITY ):SetPoint( "TOP", Text, "BOTTOM", 0, -12 );
-- Item level range
local ItemLevelMin = InitializeLevelEditBox( NS.ItemLevelMin, "ItemLevelMin", L.ITEM_LEVEL );
ItemLevelMin:SetPoint( "TOP", NS.Quality, "BOTTOM", 0, -16 );
ItemLevelMin:SetPoint( "LEFT", 16, 0 );
local ItemLevelMax = InitializeLevelEditBox( NS.ItemLevelMax, "ItemLevelMax", L.LEVELRANGE_SEPARATOR );
ItemLevelMax.Label:SetPoint( "LEFT", ItemLevelMin, "RIGHT", 2, 0 );
ItemLevelMax:SetPoint( "LEFT", ItemLevelMax.Label, "RIGHT", 8, 0 );
ItemLevelMin.Label:SetPoint( "CENTER", ItemLevelMax.Label ); -- Center above dash between edit boxes
ItemLevelMin.Label:SetPoint( "BOTTOM", ItemLevelMin, "TOP" );
-- Required level range
local ReqLevelMax = InitializeLevelEditBox( NS.ReqLevelMax, "ReqLevelMax", L.REQUIRED_LEVEL );
ReqLevelMax:SetPoint( "TOP", NS.ItemLevelMin );
ReqLevelMax:SetPoint( "RIGHT", -24, 0 );
local ReqLevelMin = InitializeLevelEditBox( NS.ReqLevelMin, "ReqLevelMin", L.LEVELRANGE_SEPARATOR );
ReqLevelMin.Label:SetPoint( "RIGHT", ReqLevelMax, "LEFT", -8, 0 );
ReqLevelMin:SetPoint( "RIGHT", ReqLevelMin.Label, "LEFT", -2, 0 );
ReqLevelMax.Label:SetPoint( "CENTER", ReqLevelMin.Label );
ReqLevelMax.Label:SetPoint( "BOTTOM", ReqLevelMax, "TOP" );
-- Item category section
local CategorySection = NS.CategorySection;
_G[ CategorySection:GetName().."Title" ]:SetText( L.ITEM_CATEGORY );
CategorySection:SetPoint( "TOP", ItemLevelMin, "BOTTOM", 0, -38 );
CategorySection:SetPoint( "LEFT", 8, 0 );
CategorySection:SetPoint( "BOTTOMRIGHT", -16, 16 );
local Background = CategorySection:CreateTexture( nil, "BACKGROUND" );
Background:SetPoint( "TOPLEFT", 4, -4 );
Background:SetPoint( "BOTTOMRIGHT", -4, 4 );
Background:SetColorTexture( 1, 1, 1, 0.2 );
InitializeDropdown( NS.Type, "Type", L.TYPE ):SetPoint( "TOP", 0, -16 );
InitializeDropdown( NS.SubType, "SubType", L.SUB_TYPE ):SetPoint( "TOP", NS.Type, "BOTTOM", 0, -6 );
InitializeDropdown( NS.Slot, "Slot", L.SLOT ):SetPoint( "TOP", NS.SubType, "BOTTOM", 0, -16 );
-- Hooks
for i = 1, 4 do
_G["GuildBankFrameTab"..i]:HookScript("OnClick", NS.GuildBankFrameTabOnClick );
end
hooksecurefunc( GuildBankFrame, "Update", NS.GuildBankFrameUpdate );
GuildBankMessageFrame.AddMessage = NS.GuildBankMessageFrameAddMessage;
ChatEdit_InsertLink = NS.ChatEditInsertLink;
NS.FilterClear();
wipe( Filter ); -- FilterClear won't fire edit box OnTextChanged handlers, so clear manually.
NS.FilterUpdate( true );
end
if isWrath then
local function OnEvent(self, event, addon)
if addon == "Blizzard_GuildBankUI" then
m:OnLoad()
end
end
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", OnEvent)
else
m:OnLoad()
end