-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFarmhand.lua
More file actions
1272 lines (1152 loc) · 40.9 KB
/
Farmhand.lua
File metadata and controls
1272 lines (1152 loc) · 40.9 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
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
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, FH = ...
local L = FH.L
FH.M = FH.M or {} -- methods
FH.E = FH.E or {} -- exports
FH._i = FH._i or {} -- internal state
local ValleyMapID,PandariaContID,_ = 376,870
local master_plow_item, master_plow_spell = 89815, 116357 -- 89880, 18499 -- DEBUG
local master_plow_buff = C_Spell.GetSpellName(master_plow_spell)
local msq, msqGroups = nil, {}
if LibStub then
msq = LibStub("Masque",true)
if msq then
msqGroups = {
FarmhandTools = msq:Group(addonName,"Tools"),
FarmhandSeeds = msq:Group(addonName,"Seeds"),
FarmhandPortals = msq:Group(addonName,"Portals"),
FarmhandTurnins = msq:Group(addonName,"Turnins"),
}
end
end
local GREEN = "|cFF00FF00"
local WHITE = "|cFFFFFFFF"
local ORANGE = "|cFFFF7F00"
local TEAL = "|cFF00FF9A"
local LABEL = format("|T134435:16|t%s%s|r:",TEAL,addonName)
local FarmhandDataDefaults = {
X = 0,
Y = -UIParent:GetHeight() / 5,
PrintScannerMessages = true,
PlayScannerSounds = true,
ShowPortals = true,
HideInCombat = true,
ShowStockTip = true,
StockTipPosition = "BELOW",
ShowVeggieIconsForSeeds = false,
ShowVeggieIconsForBags = false,
DarkSoilHelpers = true,
ShowTurnins = true,
minimap = {
hide = true,
lock = false,
minimapPos = 250,
}
}
function FH.M.Initialize()
FarmhandData = FarmhandData or CopyTable(FarmhandDataDefaults)
for k, v in pairs(FarmhandDataDefaults) do
if FarmhandData[k] == nil then
if type(v)=="table" then
FarmhandData[k] = CopyTable(v)
else
FarmhandData[k] = v
end
end
end
FarmhandMinimapHideOption:SetChecked(FarmhandData.minimap.hide)
FarmhandMessagesOption:SetChecked(FarmhandData.PrintScannerMessages)
FarmhandSoundsOption:SetChecked(FarmhandData.PlayScannerSounds)
FarmhandPortalsOption:SetChecked(FarmhandData.ShowPortals)
FarmhandTurninsOption:SetChecked(FarmhandData.ShowTurnins)
FarmhandHideInCombatOption:SetChecked(FarmhandData.HideInCombat)
FarmhandDarkSoilOption:SetChecked(FarmhandData.DarkSoilHelpers)
FarmhandStockTipOption:SetChecked(FarmhandData.ShowStockTip)
FarmhandSeedIconOption:SetChecked(FarmhandData.ShowVeggieIconsForSeeds)
FarmhandBagIconOption:SetChecked(FarmhandData.ShowVeggieIconsForBags)
FH.M.UpdateMiscToolsCheckboxes()
if not FarmhandData.ShowStockTip then UIDropDownMenu_DisableDropDown(Farmhand.StockTipPositionDropdown) end
if FarmhandData.StockTipPosition == "BELOW" then
UIDropDownMenu_SetText(Farmhand.StockTipPositionDropdown, L["Below Normal Tooltip"])
else
UIDropDownMenu_SetText(Farmhand.StockTipPositionDropdown, L["Right of Normal Tooltip"])
end
for Seed, Veggie in pairs(FH.VeggiesBySeed) do --Attempt to pre-cache item info
FH.GetItemInfo(Seed)
FH.GetItemInfo(Veggie)
end
Farmhand:SetPoint("CENTER",UIParent,"CENTER",FarmhandData.X,FarmhandData.Y)
FarmhandSeeds.Update = FH.M.UpdateBar
FarmhandTools.Update = FH.M.UpdateBar
FarmhandPortals.Update = FH.M.UpdateBar
FarmhandTurnins.Update = FH.M.UpdateBar
hooksecurefunc(GameTooltip, "SetMerchantItem", FH.M.SetMerchantItemTooltip)
GameTooltip:HookScript("OnTooltipSetUnit",FH.M.SetUnitTooltip)
hooksecurefunc(GameTooltip, "SetBagItem", FH.M.SetBagItemTooltip)
hooksecurefunc(GameTooltip, "SetTradeSkillItem", FH.M.SetTradSkillItemTooltip)
GameTooltip:HookScript("OnHide", FH.M.HideExtraTooltip)
hooksecurefunc(C_CVar, "SetCVar", FH.M.PostHookSetCVar)
FH.LDB = LibStub("LibDataBroker-1.1",true)
FH.LDBIcon = LibStub("LibDBIcon-1.0",true)
if FH.LDB and FH.LDBIcon then
FH.LDBObject = FH.LDB:NewDataObject(addonName,
{
type = "launcher",
text = addonName,
icon = 609616,
label = "FH",
OnTooltipShow = FH.M.OnLDBIconTooltipShow,
OnClick = FH.M.OnLDBIconClick,
})
FH.LDBIcon:Register(addonName, FH.LDBObject, FarmhandData.minimap)
end
FH.LQTip1_0 = LibStub("LibQTip-1.0",true)
end
function FH.M.IsOptionEnabled(option)
if option == "minimap.hide" then
return FarmhandData.minimap.hide
elseif option == "minimap.lock" then
return FarmhandData.minimap.lock
else
return FarmhandData[option]
end
end
function FH.M.ToggleQuickOption(option)
if option == "minimap.hide" then
FH.M.SetMinimapHideOption(not FarmhandData.minimap.hide)
elseif option == "minimap.lock" then
FH.M.SetMinimapLockOption(not FarmhandData.minimap.lock)
elseif option == "PrintScannerMessages" then
FH.M.SetMessagesOption(not FarmhandData.PrintScannerMessages)
elseif option == "PlayScannerSounds" then
FH.M.SetSoundsOption(not FarmhandData.PlayScannerSounds)
elseif option == "ShowStockTip" then
FH.M.SetStockTipOption(not FarmhandData.ShowStockTip)
elseif option == "ShowPortals" then
FH.M.SetPortalsOption(not FarmhandData.ShowPortals)
elseif option == "ShowTurnins" then
FH.M.SetTurninsOption(not FarmhandData.ShowTurnins)
elseif option == "HideInCombat" then
FH.M.SetHideInCombatOption(not FarmhandData.HideInCombat)
elseif option == "DarkSoilHelpers" then
FH.M.SetDarkSoilOption(not FarmhandData.DarkSoilHelpers)
end
end
function FH.M.OnLDBIconTooltipShow(tip)
local tip = tip or GameTooltip
tip:SetText(LABEL)
tip:AddDoubleLine(L["Left-Click"],L["Clear TomTom Waypoints"],1,0.65,0,1,1,0,false)
tip:AddDoubleLine(L["Right-Click"],L["Quick Options"],1,0.65,0,1,1,0,false)
tip:AddDoubleLine(L["Middle-Click"],L["Blizzard Options"],1,0.65,0,1,1,0,false)
end
function FH.M.OnLDBIconClick(frame, mouseButton, Down)
if mouseButton == "LeftButton" then
if FH.M.RemoveAllWaypoints then
FH.M.RemoveAllWaypoints()
end
elseif mouseButton == "RightButton" then
local menu = MenuUtil.CreateCheckboxContextMenu(frame,
FH.M.IsOptionEnabled,
FH.M.ToggleQuickOption,
{L["Chat info messages"],"PrintScannerMessages"},
{L["Notification sounds"],"PlayScannerSounds"},
{L["Extra tooltip"],"ShowStockTip"},
{L["Portal shard icons"],"ShowPortals"},
{L["Turn-in icons"],"ShowTurnins"},
{L["Auto-hide in combat"],"HideInCombat"},
{L["Dark Soil helpers"],"DarkSoilHelpers"},
{L["Hide Minimap icon"],"minimap.hide"},
{L["Lock Minimap icon"],"minimap.lock"}
)
elseif mouseButton == "MiddleButton" then
Settings.OpenToCategory(FH.optionsCategory:GetID())
end
end
function FH.M.GetExtraTooltip()
if FH.LQTip1_0 then
if not FH.LQTip1_0:IsAcquired(addonName.."QTip_1.0") then
FH.QTip = FH.LQTip1_0:Acquire(addonName.."QTip_1.0",3,"LEFT","LEFT","LEFT")
else
FH.QTip:Clear()
end
end
return FH.QTip
end
function FH.M.HideExtraTooltip(anchor)
if FH.LQTip1_0:IsAcquired(addonName.."QTip_1.0") then
FH.LQTip1_0:Release(FH.QTip)
end
end
function FH.M.UpdateMiscToolsCheckboxes()
local AllChecked = true
local Choices = FarmhandData.ShowMiscTools or {}
local btn
for _, v in ipairs(FH.MiscTools) do
btn = _G["FarmhandMiscToolsOption"..v]
if btn then
btn:SetChecked(Choices[v] or false)
AllChecked = AllChecked and Choices[v] or false
end
end
btn = _G["FarmhandMiscToolsOption"]
btn:SetChecked(AllChecked)
end
function FH.M.MerchantEvent(MerchantOpen)
FH.MerchantOpen = MerchantOpen
end
function FH.M.HandlePlayerCast(spellid)
-- master plow handling
if spellid == master_plow_spell then
FH._i.masterPlowActive = true
local cdInfo = FH.GetSpellCooldown(master_plow_spell)
if cdInfo then
if (cdInfo.startTime > 0 and cdInfo.duration > 0) then
local cdLeft = cdInfo.startTime + cdInfo.duration - GetTime()
if cdLeft and cdLeft > 0 then
C_Timer.After(cdLeft, function() FH._i.masterPlowActive = false end)
end
end
end
end
end
function FH.M.PostHookSetCVar(cvar, value)
if not (cvar:lower() == "graphicsgroundclutter") then return end
if FH._i.cvarChanged then return end -- we only care for player changes
FH._i.cvarOrig = value
end
local itemCounts = {}
local itemCountsLabels = { L["Bags"], L["Bank"], L["AH"], L["Mail"] }
local function AddCharacterCountLine(character, searchedID)
itemCounts[1], itemCounts[2] = DataStore:GetContainerItemCount(character, searchedID)
itemCounts[3] = DataStore:GetAuctionHouseItemCount(character, searchedID)
itemCounts[4] = DataStore:GetMailItemCount(character, searchedID)
local charCount = 0
for _, v in pairs(itemCounts) do
charCount = charCount + v
end
if charCount > 0 then
local account, _, char = strsplit(".", character)
local name = DataStore:GetColoredCharacterName(character) or char -- if for any reason this char isn't in DS_Characters.. use the name part of the key
local t = {}
for k, v in pairs(itemCounts) do
if v > 0 then -- if there are more than 0 items in this container
table.insert(t, WHITE .. itemCountsLabels[k] .. ": " .. TEAL .. v)
end
end
-- charInfo should look like (Bags: 4, Bank: 8, Equipped: 1, Mail: 7), table concat takes care of this
if FH.QTip then
local line, col = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,name)
FH.QTip:SetCell(line,2,format("%s (%s%s)", ORANGE .. charCount .. WHITE, table.concat(t, WHITE..", "), WHITE))
end
end
end
function FH.M.ParseGUID(guid)
if not guid or guid == "" then return end
local guidType, arg2, arg3, arg4, arg5, arg6, arg7 = ("-"):split(guid)
local npcid = 0
guidType = guidType or ""
if guidType == "Creature" then
local _, serverID, instanceID, zoneUID, npc, spawnUID = arg2, arg3, arg4, arg5, arg6, arg7
npcid = npc and tonumber(npc) or 0
end
return npcid, guidType
end
function FH.M.IsCookingOpen()
if not TradeSkillFrame:IsVisible() then return end
local prof1, prof2, arch, fishing, cooking, firstaid = GetProfessions()
if not cooking then return end
local cookingName = GetProfessionInfo(cooking)
local tradeSkill = GetTradeSkillLine()
if tradeSkill and cookingName and (tradeSkill == cookingName) then
return true
end
end
function FH.M.SetUnitTooltip(tooltip, unitid)
if not (FarmhandData.ShowStockTip and FH.InValley) then
return
end
local tooltip = tooltip or GameTooltip
local name,unitid = tooltip:GetUnit()
local npcid = FH.M.ParseGUID(UnitGUID(unitid or "none"))
if npcid and FH.NpcInfo[npcid] then
if not tooltip and tooltip.GetCenter then return end
FH.QTip = FH.M.GetExtraTooltip()
--FH.QTip:SmartAnchorTo(tooltip)
FH.QTip:ClearAllPoints()
if FarmhandData.StockTipPosition == "BELOW" then
FH.QTip:SetPoint("TOPLEFT", tooltip, "BOTTOMLEFT")
else
FH.QTip:SetPoint("TOPLEFT", tooltip, "TOPRIGHT")
end
local info = FH.M.GetUnitTooltipData(npcid)
if info then
local line, col = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["Likes"])
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,info.gift,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,1)
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["Eats"])
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,info.foodgift.food.."(x5)",nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,1)
for material,amount in pairs(info.foodgift.craft) do
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1," ")
FH.QTip:SetCell(line,2,material .. format("x%d(%d)",amount,amount*5),nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,0.7,0.7,0.7)
end
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["Best Friend"])
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,info.reward,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,1)
FH.QTip:Show()
end
else
FH.M.HideExtraTooltip(tooltip)
end
end
function FH.M.SetTradSkillItemTooltip(tooltip, skillIndex)
if not (FarmhandData.ShowStockTip) then return end
if not FH.M.IsCookingOpen() then return end
local tooltip = tooltip or GameTooltip
local itemlink = GetTradeSkillItemLink(skillIndex)
local _,ttItemlink = tooltip:GetItem()
local itemID = itemlink and FH.GetItemInfoInstant(itemlink)
local testID = ttItemlink and FH.GetItemInfoInstant(ttItemlink)
if itemID and testID and (itemID == testID) then
if not FH.TurninFood[itemID] then return end
if not tooltip and tooltip.GetCenter then return end
FH.QTip = FH.M.GetExtraTooltip()
--FH.QTip:SmartAnchorTo(tooltip)
FH.QTip:ClearAllPoints()
if FarmhandData.StockTipPosition == "BELOW" then
FH.QTip:SetPoint("TOPLEFT", tooltip, "BOTTOMLEFT")
else
FH.QTip:SetPoint("TOPLEFT", tooltip, "TOPRIGHT")
end
local info = FH.M.GetBagItemTooltipData(itemID)
if info then
local line, col
for npcid,data in pairs(info) do
if npcid ~= "craft" then
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,data.npc)
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,data.reaction,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,0)
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["Best Friend"])
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,data.reward,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,1)
end
end
FH.QTip:Show()
end
else
FH.M.HideExtraTooltip(tooltip)
end
end
function FH.M.SetBagItemTooltip(tooltip, bag, slot)
if not (FarmhandData.ShowStockTip) then return end
local tooltip = tooltip or GameTooltip
local itemID = FH.GetContainerItemID(bag, slot)
if not itemID then return end
if not (FH.TurninGift[itemID] or FH.TurninFood[itemID] or FH.FoodGiftIngredient) then return end
if not tooltip and tooltip.GetCenter then return end
FH.QTip = FH.M.GetExtraTooltip()
--FH.QTip:SmartAnchorTo(tooltip)
FH.QTip:ClearAllPoints()
if FarmhandData.StockTipPosition == "BELOW" then
FH.QTip:SetPoint("TOPLEFT", tooltip, "BOTTOMLEFT")
else
FH.QTip:SetPoint("TOPLEFT", tooltip, "TOPRIGHT")
end
local line, col
if FH.TurninGift[itemID] then
local info = FH.M.GetBagItemTooltipData(itemID)
if info then
for npcid,data in pairs(info) do
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,data.npc)
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,data.reaction,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,0)
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["Best Friend"])
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,data.reward,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,1)
end
FH.QTip:Show()
end
elseif FH.TurninFood[itemID] then
local info = FH.M.GetBagItemTooltipData(itemID)
if info then
if info.craft then
for ingredient,amount in pairs(info.craft) do
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1," ")
FH.QTip:SetCell(line,2,format("%sx%d",ingredient,amount),nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,0.7,0.7,0.7)
end
end
for npcid,data in pairs(info) do
if npcid ~= "craft" then
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,data.npc)
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,data.reaction,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,0)
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["Best Friend"])
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,data.reward,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,1)
end
end
FH.QTip:Show()
end
elseif FH.FoodGiftIngredient[itemID] then
local info = FH.M.GetBagItemTooltipData(itemID)
if info then
for foodgift,data in pairs(info) do
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,data.amount)
FH.QTip:SetCellTextColor(line,1,0.7,0.7,0.7)
FH.QTip:SetCell(line,2,data.food,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,1,1,1)
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1," ")
FH.QTip:SetCell(line,2,data.npc,nil,"RIGHT")
FH.QTip:SetCellTextColor(line,2,0,1,0)
end
FH.QTip:Show()
end
else
FH.M.HideExtraTooltip(tooltip)
end
end
function FH.M.SetMerchantItemTooltip(tooltip, slot)
if ( MerchantFrame.selectedTab == 1 ) and FarmhandData.ShowStockTip and FH.MerchantOpen then
local tooltip = tooltip or GameTooltip
local ItemID = GetMerchantItemID(slot)
if ItemID == nil then return end
local VeggieID = FH.VeggiesBySeed[ItemID]
if VeggieID == nil then
ItemID = FH.SeedsBySeedBag[ItemID]
if ItemID == nil then return end
VeggieID = FH.VeggiesBySeed[ItemID]
end
if VeggieID then
local veggieName = FH.GetItemInfo(VeggieID)
local onHand = FH.GetItemCount(VeggieID,false)
local inBank = FH.GetItemCount(VeggieID,true) - onHand
local icon = FH.GetItemIcon(VeggieID)
icon = icon and "|T"..icon..":14:14:0:0:32:32:3:29:3:29|t" or "??"
veggieName = veggieName and icon.." "..veggieName or icon.." ".."ItemID: "..VeggieID
if not tooltip and tooltip.GetCenter then return end
FH.QTip = FH.M.GetExtraTooltip()
--FH.QTip:SmartAnchorTo(tooltip)
FH.QTip:ClearAllPoints()
if FarmhandData.StockTipPosition == "BELOW" then
FH.QTip:SetPoint("TOPLEFT", tooltip, "BOTTOMLEFT")
else
FH.QTip:SetPoint("TOPLEFT", tooltip, "TOPRIGHT")
end
local line, col = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["Produces"])
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,veggieName)
FH.QTip:SetCellTextColor(line,2,1,1,1)
if DataStore then
line = FH.QTip:AddLine(" ")
local ThisChar = DataStore:GetCharacter()
AddCharacterCountLine(ThisChar,VeggieID)
line = FH.QTip:AddLine(" ")
for name, character in pairs(DataStore:GetCharacters(GetRealmName(), "Default")) do
if name ~= UnitName("player") and DataStore:GetCharacterFaction(character) == UnitFactionGroup("player") then
AddCharacterCountLine(character, VeggieID)
end
end
line = FH.QTip:AddLine(" ")
for guildName, guildKey in pairs(DataStore:GetGuilds(GetRealmName())) do -- this realm only
local guildCount = DataStore:GetGuildBankItemCount(guildKey, VeggieID) or 0
if guildCount > 0 then
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,GREEN..guildName)
FH.QTip:SetCell(line,2,format("%s(%s: %s%s)", WHITE, "Guild Bank", TEAL..guildCount, WHITE))
end
end
else
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["On Hand"])
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,onHand)
FH.QTip:SetCellTextColor(line,2,1,1,1)
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["In Bank"])
FH.QTip:SetCellTextColor(line,1,0,1,0)
FH.QTip:SetCell(line,2,inBank)
FH.QTip:SetCellTextColor(line,2,1,1,1)
end
local copper
if Auctionator and Auctionator.API and Auctionator.API.v1 then
copper = Auctionator.API.v1.GetAuctionPriceByItemID(addonName, VeggieID)
elseif TSM_API and TSM_API.GetCustomPriceValue then
copper = TSM_API.GetCustomPriceValue("dbminbuyout", "i:"..VeggieID)
end
if copper then
local moneyString = GetMoneyString(copper)
line = FH.QTip:AddLine()
FH.QTip:SetCell(line,1,L["Market Price"])
FH.QTip:SetCellTextColor(line,1,1,1,0)
FH.QTip:SetCell(line,2,moneyString)
end
FH.QTip:Show()
else
FH.M.HideExtraTooltip(tooltip)
end
end
end
function FH.M.ZoneChanged()
local Zone, SubZone = GetZoneText(), GetSubZoneText()
local InSunsong = SubZone == L["Sunsong Ranch"]
local InMarket = SubZone == L["The Halfhill Market"]
local InHalfhill = InSunsong or InMarket or SubZone == L["Halfhill"] or Zone == L["Halfhill"]
local ShowTurnins = FarmhandData.ShowTurnins and FH.M.CheckInValley()
if FarmhandData.DarkSoilHelpers then
FH.M.SetDarkSoilHelpers()
else
FH.M.ResetDarkSoilHelpers()
end
if not (InHalfhill or FH.InHalfhill or FarmhandData.ShowTurnins) then return end
local LeavingHalfhill = not InHalfhill and FH.InHalfhill
local EnteringSunsong = InSunsong and not FH.InSunsong
local LeavingSunsong = not InSunsong and FH.InSunsong
local EnteringMarket = InMarket and not FH.InMarket
local LeavingMarket = not InMarket and FH.InMarket
if ((LeavingSunsong or LeavingMarket) and not (EnteringSunsong or EnteringMarket)) then
Farmhand:UnregisterEvent("MERCHANT_SHOW")
Farmhand:UnregisterEvent("MERCHANT_CLOSED")
Farmhand:UnregisterEvent("MERCHANT_UPDATE")
FarmhandSeeds:Hide()
FarmhandTools:Hide()
FarmhandPortals:Hide()
if not (ShowTurnins) then
Farmhand:UnregisterEvent("BAG_UPDATE_DELAYED")
FarmhandTurnins:Hide()
Farmhand:Hide()
UnregisterStateDriver(Farmhand,"visibility")
end
end
if ((EnteringSunsong or EnteringMarket) and not (FH.InSunsong or FH.InMarket)) or ShowTurnins then
Farmhand:RegisterEvent("BAG_UPDATE_DELAYED")
if ((EnteringSunsong or EnteringMarket) and not (FH.InSunsong or FH.InMarket)) then
Farmhand:RegisterEvent("MERCHANT_SHOW")
Farmhand:RegisterEvent("MERCHANT_CLOSED")
Farmhand:RegisterEvent("MERCHANT_UPDATE")
FarmhandSeeds:Show()
end
if ShowTurnins then
FarmhandTurnins:Show()
end
Farmhand:Show()
if FarmhandData.HideInCombat then
RegisterStateDriver(Farmhand,"visibility","[combat]hide;show")
end
end
if EnteringSunsong then
FarmhandTools:Show()
if FarmhandData.ShowPortals then FarmhandPortals:Show() end
Farmhand:RegisterEvent("BAG_UPDATE_COOLDOWN")
if FH.GetItemCount(master_plow_item) > 0 then
Farmhand:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED","player")
else
Farmhand:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
FH._i.masterPlowActive = false
end
elseif LeavingSunsong then
if not ShowTurnins then
Farmhand:UnregisterEvent("BAG_UPDATE_COOLDOWN")
end
FarmhandTools:Hide()
FarmhandPortals:Hide()
Farmhand:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
FH._i.masterPlowActive = false
end
if not (ShowTurnins) then
FarmhandTurnins:Hide()
end
if EnteringSunsong or EnteringMarket or ShowTurnins then
Farmhand:Show()
FH.M.Update()
end
FH.InHalfhill = InHalfhill
FH.InMarket = InMarket
FH.InSunsong = InSunsong
end
function FH.M.LootDarkSoil(autoLoot)
local numLoot = GetNumLootItems()
if numLoot == 0 then return end
local autoLooting = autoLoot or (GetCVarBool("autoLootDefault") ~= IsModifiedClick("AUTOLOOTTOGGLE"))
for slot=numLoot,1,-1 do
if LootSlotHasItem(slot) then
local itemLink = GetLootSlotLink(slot)
if (itemLink) then
local itemID = C_Item.GetItemInfoInstant(itemLink)
if itemID and FH.DarkSoil.contents[itemID] then
if not autoLooting then
LootSlot(slot)
end
ConfirmLootSlot(slot)
local dialog = StaticPopup_FindVisible("LOOT_BIND")
if dialog then
if dialog.GetButton1 then
dialog:GetButton1():Click()
else
if _G[dialog:GetName().."Button1"] then
_G[dialog:GetName().."Button1"]:Click()
end
end
end
end
end
end
end
end
function FH.M.SetDarkSoilHelpers()
if FH.M.CheckInValley() then
FH._i.cvarChanged = true
local from = C_CVar.GetCVar("graphicsGroundClutter")
if from ~= "0" then
FH._i.cvarOrig = from
C_CVar.SetCVar("graphicsGroundClutter","0")
C_Timer.After(0.2, function() FH._i.cvarChanged = false end)
end
Farmhand:RegisterEvent("LOOT_READY")
if not FH._i.tooltipHook then
GameTooltip:HookScript("OnShow", FH.M.SearchInTooltip)
end
FH._i.searchTooltip = true
else
FH.M.ResetDarkSoilHelpers()
end
end
function FH.M.ResetDarkSoilHelpers(logout)
if FH._i.cvarOrig then
if not logout then
FH._i.cvarChanged = true
end
C_CVar.SetCVar("graphicsGroundClutter",FH._i.cvarOrig)
C_Timer.After(0.2, function() FH._i.cvarChanged = false end)
end
Farmhand:UnregisterEvent("LOOT_READY")
FH._i.searchTooltip = false
end
function FH.M.CheckInValley()
local mapID = C_Map.GetBestMapForUnit("player")
local mapInfo = mapID and C_Map.GetMapInfo(mapID)
FH.InValley = false
if mapID and mapInfo then
if mapID == ValleyMapID then
FH.InValley = true
return FH.InValley
else
if mapInfo.mapType == Enum.UIMapType.Micro then
mapID = mapInfo.parentMapID
if mapID == ValleyMapID then
FH.InValley = true
return FH.InValley
end
end
end
end
return FH.InValley
end
function FH.M.CheckInPandaria()
local mapID = C_Map.GetBestMapForUnit("player")
local mapPosition = mapID and C_Map.GetPlayerMapPosition(mapID,"player")
FH.InPandaria = false
if mapID and mapPosition then
local contID, position = C_Map.GetWorldPosFromMapPos(mapID,mapPosition)
if contID and contID == PandariaContID then
FH.InPandaria = true
return FH.InPandaria
end
end
return FH.InPandaria
end
function FH.M.ItemPreClick(Button,MouseButton,Down)
if Down and not InCombatLockdown() then
local Bag, Slot = FH.M.FindItemInBags(Button.ItemID)
if IsShiftKeyDown() then
Button:SetAttribute("type",nil)
elseif FH.InSunsong then
if Button.ItemType == "Seed" and UnitName("target") ~= L["Tilled Soil"] then
Button:SetAttribute("type","macro")
Button:SetAttribute("macrotext","/targetexact "..L["Tilled Soil"].."\n/use "..Bag.." "..Slot)
elseif Button.ItemType == "FarmTool" and Button.ItemID == master_plow_item then
if FH._i.masterPlowActive then
Button:SetAttribute("type","macro")
Button:SetAttribute("macrotext","/cancelaura "..master_plow_buff)
end
elseif Button.ItemType ~= "Turnin" then
Button:SetAttribute("type","item")
Button:SetAttribute("item",Bag.." "..Slot)
end
else
if Button.ItemType ~= "Turnin" then
Button:SetAttribute("type","item")
Button:SetAttribute("item",Bag.." "..Slot)
end
end
end
end
function FH.M.ItemPostClick(Button,MouseButton,Down)
if Down then return end
if not InCombatLockdown() then
if Button.ItemType ~= "Turnin" then
Button:SetAttribute("type","item")
Button:SetAttribute("item","item:"..Button.ItemID)
if Button.ItemType == "FarmTool" and Button.ItemID == master_plow_item then
local cdInfo = FH.GetSpellCooldown(master_plow_spell)
if cdInfo then
if (cdInfo.startTime > 0 and cdInfo.duration > 0) then
Button.Cooldown:SetCooldown(cdInfo.startTime, cdInfo.duration, cdInfo.modRate)
else
Button.Cooldown:Clear()
end
else
Button.Cooldown:Clear()
end
FH._i.masterPlowActive = false
end
end
Button:SetAttribute("shift-item*","")
end
if Button.ItemType == "Turnin" then
if MouseButton == "LeftButton" then
if FH.M.AddGiftWaypoint and Button.ItemID then
FH.M.AddGiftWaypoint(Button.ItemID)
end
elseif MouseButton == "RightButton" then
if FH.M.RemoveGiftWaypoint and Button.ItemID then
FH.M.RemoveGiftWaypoint(Button.ItemID)
end
end
end
end
function FH.M.ItemOnEnter(Button)
if FH.MerchantOpen and Button.ItemType == "Seed" then
FH.ShowContainerSellCursor(Button.Bag,Button.Slot)
end
GameTooltip_SetDefaultAnchor(GameTooltip, UIParent)
GameTooltip:SetBagItem(Button.Bag,Button.Slot)
if Button.ItemType == "Turnin" then
GameTooltip:AddDoubleLine(L["Left-Click for Directions"],L["Right-Click to Clear"],0,1,0,1,1,0,false)
end
GameTooltip:Show()
end
function FH.M.ItemOnLeave(Button)
if FH.MerchantOpen and Button.ItemType == "Seed" then
ResetCursor()
end
GameTooltip_Hide()
end
function FH.M.AlertWithThrottle(interval)
local now = GetTime()
if (not FH._i.lastAlert) or ((now - FH._i.lastAlert) > interval) then
FH._i.lastAlert = now
if FarmhandData.PlayScannerSounds then
PlaySoundFile(567574,"SFX")
end
if FarmhandData.PrintScannerMessages then
local msg = format("Found "..GREEN.."%s|r Nearby.",FH.DarkSoil.name)
FH.M.Print(msg)
end
end
end
function FH.M.SearchInTooltip(self)
local self = self or GameTooltip
if not FH._i.searchTooltip then return end
if self:GetItem() or self:GetSpell() or self:GetUnit() then return end
if WorldMapFrame and WorldMapFrame:IsVisible() and WorldMapFrame:IsMouseOver() then return end
if WatchFrame and WatchFrame:IsVisible() and WatchFrame:IsMouseOver() then return end
if Minimap and Minimap:IsVisible() and Minimap:IsMouseOver() then return end
local chatFrame = (DEFAULT_CHAT_FRAME or SELECTED_CHAT_FRAME)
if chatFrame:IsVisible() and chatFrame:IsMouseOver() then return end
local fString = _G[self:GetName().."TextLeft1"]
local leftText = fString and fString.GetText and fString:GetText() or ""
if leftText and strfind(leftText, FH.DarkSoil.name) then
FH.M.AlertWithThrottle(5)
return true
end
end
function FH.M.ButtonOnMouseDown(Button, MouseButton)
if IsShiftKeyDown() and MouseButton == "LeftButton" and not Farmhand.isMoving then
_,_,_, Farmhand.InitialOffsetX, Farmhand.InitialOffsetY = Farmhand:GetPoint(1)
Farmhand:StartMoving()
_,_,_, Farmhand.PickupOffsetX, Farmhand.PickupOffsetY = Farmhand:GetPoint(1)
Farmhand.isMoving = true
elseif MouseButton == "RightButton" and Farmhand.isMoving then
Farmhand:StopMovingOrSizing()
Farmhand.isMoving = false
FarmhandData.X, FarmhandData.Y = 0, - UIParent:GetHeight() / 5
FH.M.RunAfterCombat(FH.M.ResetAnchors)
end
end
function FH.M.ButtonOnMouseUp(Button, MouseButton)
if MouseButton == "LeftButton" and Farmhand.isMoving then
local _,_,_, DropOffsetX, DropOffsetY = Farmhand:GetPoint(1)
Farmhand:StopMovingOrSizing()
Farmhand.isMoving = false
FarmhandData.X = DropOffsetX - Farmhand.PickupOffsetX + Farmhand.InitialOffsetX
FarmhandData.Y = DropOffsetY - Farmhand.PickupOffsetY + Farmhand.InitialOffsetY
FH.M.RunAfterCombat(FH.M.ResetAnchors)
end
end
function FH.M.ResetAnchors()
Farmhand:ClearAllPoints()
Farmhand:SetPoint("CENTER",UIParent,FarmhandData.X,FarmhandData.Y)
end
function FH.M.ButtonOnHide()
if InCombatLockdown() then
FH.M.RunAfterCombat(FH.M.ButtonOnHide)
return
end
if Farmhand.isMoving then
Farmhand:StopMovingOrSizing()
Farmhand.isMoving = false
FH.M.RunAfterCombat(FH.M.ResetAnchors)
end
end
function FH.M.SetHideInCombatOption(Value)
FarmhandData.HideInCombat = Value
if Value and Farmhand:IsShown() then
RegisterStateDriver(Farmhand,"visibility","[combat]hide;show")
else
UnregisterStateDriver(Farmhand,"visibility")
end
end
function FH.M.SetDarkSoilOption(Value)
FarmhandData.DarkSoilHelpers = Value
if Value then
FH.M.SetDarkSoilHelpers()
else
FH.M.ResetDarkSoilHelpers()
end
end
function FH.M.SetBagIconOption(Value)
FarmhandData.ShowVeggieIconsForBags = Value
FH.M.UpdateButtonIcons(FarmhandSeeds)
end
function FH.M.SetSeedIconOption(Value)
FarmhandData.ShowVeggieIconsForSeeds = Value
FH.M.UpdateButtonIcons(FarmhandSeeds)
end
function FH.M.SetStockTipOption(Value)
FarmhandData.ShowStockTip = Value
if FarmhandData.ShowStockTip then
UIDropDownMenu_EnableDropDown(Farmhand.StockTipPositionDropdown)
else
UIDropDownMenu_DisableDropDown(Farmhand.StockTipPositionDropdown)
end
end
function FH.M.InitializeStockTipDropdown(frame, level, menuList)
local info = UIDropDownMenu_CreateInfo()
info.func = FH.M.SetStockTipPosition
info.text = L["Below Normal Tooltip"]
info.value = "BELOW"
info.checked = FarmhandData and FarmhandData.StockTipPosition == "BELOW" or FarmhandData == nil and false
UIDropDownMenu_AddButton(info)
info.text = L["Right of Normal Tooltip"]
info.value = "RIGHT"
info.checked = FarmhandData and FarmhandData.StockTipPosition == "RIGHT"
UIDropDownMenu_AddButton(info)
end
function FH.M.SetStockTipPosition(info)
FarmhandData.StockTipPosition = info.value
if FarmhandData.StockTipPosition == "BELOW" then
UIDropDownMenu_SetText(Farmhand.StockTipPositionDropdown, L["Below Normal Tooltip"])
else
UIDropDownMenu_SetText(Farmhand.StockTipPositionDropdown, L["Right of Normal Tooltip"])
end
end
function FH.M.SetMinimapHideOption(Value)
FarmhandData.minimap.hide = Value
if FarmhandData.minimap.hide then
FH.LDBIcon:Hide(addonName)
else
FH.LDBIcon:Show(addonName)
end
end
function FH.M.SetMinimapLockOption(Value)
FarmhandData.minimap.lock = Value
if FarmhandData.minimap.lock then
FH.LDBIcon:Lock(addonName)
else
FH.LDBIcon:Unlock(addonName)
end
end
function FH.M.SetMessagesOption(Value)
FarmhandData.PrintScannerMessages = Value
end
function FH.M.SetSoundsOption(Value)
FarmhandData.PlayScannerSounds = Value
end
function FH.M.SetPortalsOption(Value)
FarmhandData.ShowPortals = Value
FH.M.ZoneChanged()
if Value then