forked from alarofrunetotem/ChampionCommander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
missionlist.lua
1510 lines (1481 loc) · 51.5 KB
/
missionlist.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
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 __FILE__=tostring(debugstack(1,2,0):match("(.*):1:")) -- Always check line number in regexp and file, must be 1
--@debug@
print('Loaded',__FILE__)
--@end-debug@
local function pp(...) print(GetTime(),"|cff009900",__FILE__:sub(-15),strjoin(",",tostringall(...)),"|r") end
--*TYPE module
--*CONFIG noswitch=false,profile=true,enhancedProfile=true
--*MIXINS "AceHook-3.0","AceEvent-3.0","AceTimer-3.0"
--*MINOR 35
-- Auto Generated
local me,ns=...
if ns.die then return end
local addon=ns --#Addon (to keep eclipse happy)
ns=nil
local module=addon:NewSubModule('Missionlist',"AceHook-3.0","AceEvent-3.0","AceTimer-3.0") --#Module
function addon:GetMissionlistModule() return module end
-- Template
local G=C_Garrison
local _
local AceGUI=LibStub("AceGUI-3.0")
local C=addon:GetColorTable()
local L=addon:GetLocale()
local new=addon:Wrap("NewTable")
local del=addon:Wrap("DelTable")
local kpairs=addon:Wrap("Kpairs")
local empty=addon:Wrap("Empty")
local todefault=addon:Wrap("todefault")
local tonumber=tonumber
local type=type
local OHF=BFAMissionFrame
local OHFMissionTab=BFAMissionFrame.MissionTab --Container for mission list and single mission
local OHFMissions=BFAMissionFrame.MissionTab.MissionList -- same as BFAMissionFrameMissions Call Update on this to refresh Mission Listing
local OHFFollowerTab=BFAMissionFrame.FollowerTab -- Contains model view
local OHFFollowerList=BFAMissionFrame.FollowerList -- Contains follower list (visible in both follower and mission mode)
local OHFFollowers=BFAMissionFrameFollowers -- Contains scroll list
local OHFMissionPage=BFAMissionFrame.MissionTab.MissionPage -- Contains mission description and party setup
local OHFMapTab=BFAMissionFrame.MapTab -- Contains quest map
local OHFMissionFrameMissions=BFAMissionFrameMissions
local OHFCompleteDialog=BFAMissionFrameMissions.CompleteDialog
local OHFMissionScroll=BFAMissionFrameMissionsListScrollFrame
local OHFMissionScrollChild=BFAMissionFrameMissionsListScrollFrameScrollChild
local OHFTOPLEFT=OHF.GarrCorners.TopLeftGarrCorner
local OHFTOPRIGHT=OHF.GarrCorners.TopRightGarrCorner
local OHFBOTTOMLEFT=OHF.GarrCorners.BottomTopLeftGarrCorner
local OHFBOTTOMRIGHT=OHF.GarrCorners.BottomRightGarrCorner
local followerType=Enum.GarrisonFollowerType.FollowerType_8_0
local garrisonType=Enum.GarrisonType.Type_8_0
local FAKE_FOLLOWERID="0x0000000000000000"
local MAX_LEVEL=110
local ShowTT=ChampionCommanderMixin.ShowTT
local HideTT=ChampionCommanderMixin.HideTT
local dprint=print
local ddump
--@debug@
LoadAddOn("Blizzard_DebugTools")
ddump=DevTools_Dump
LoadAddOn("LibDebug")
if LibDebug then LibDebug() dprint=print end
local safeG=addon.safeG
--@end-debug@
--[===[@non-debug@
dprint=function() end
ddump=function() end
local print=function() end
--@end-non-debug@]===]
local GARRISON_FOLLOWER_COMBAT_ALLY=GARRISON_FOLLOWER_COMBAT_ALLY
local GARRISON_FOLLOWER_ON_MISSION=GARRISON_FOLLOWER_ON_MISSION
local GARRISON_FOLLOWER_INACTIVE=GARRISON_FOLLOWER_INACTIVE
local GARRISON_FOLLOWER_IN_PARTY=GARRISON_FOLLOWER_IN_PARTY
local GARRISON_FOLLOWER_AVAILABLE=AVAILABLE
local ViragDevTool_AddData=_G.ViragDevTool_AddData
if not ViragDevTool_AddData then ViragDevTool_AddData=function() end end
local KEY_BUTTON1 = "\124TInterface\\TutorialFrame\\UI-Tutorial-Frame:12:12:0:0:512:512:10:65:228:283\124t" -- left mouse button
local KEY_BUTTON2 = "\124TInterface\\TutorialFrame\\UI-Tutorial-Frame:12:12:0:0:512:512:10:65:330:385\124t" -- right mouse button
local CTRL_KEY_TEXT,SHIFT_KEY_TEXT=CTRL_KEY_TEXT,SHIFT_KEY_TEXT
local CTRL_KEY_TEXT,SHIFT_KEY_TEXT=CTRL_KEY_TEXT,SHIFT_KEY_TEXT
local CTRL_SHIFT_KEY_TEXT=CTRL_KEY_TEXT .. '-' ..SHIFT_KEY_TEXT
local format,pcall=format,pcall
local function safeformat(mask,...)
local rc,result=pcall(format,mask,...)
if not rc then
for k,v in pairs(L) do
if v==mask then
mask=k
break
end
end
end
rc,result=pcall(format,mask,...)
return rc and result or mask
end
-- End Template - DO NOT MODIFY ANYTHING BEFORE THIS LINE
--*BEGIN
local _G=_G
local XP_GAIN= XP_GAIN .. ' x %d'
local pairs,wipe,tinsert,unpack=pairs,wipe,tinsert,unpack
local UNCAPPED_PERC=PERCENTAGE_STRING
local CAPPED_PERC=PERCENTAGE_STRING .. "**"
local Dialog = LibStub("LibDialog-1.0")
local missionNonFilled=true
local wipe=wipe
local GetTime=GetTime
local ENCOUNTER_JOURNAL_SECTION_FLAG4=ENCOUNTER_JOURNAL_SECTION_FLAG4
local RESURRECT=RESURRECT
local LOOT=LOOT
local IGNORED=IGNORED
local UNUSED=UNUSED
local GARRISON_FOLLOWER_COMBAT_ALLY=GARRISON_FOLLOWER_COMBAT_ALLY
local nobonusloot=G.GetFollowerAbilityDescription(471)
local increasedcost=G.GetFollowerAbilityDescription(472)
local increasedduration=G.GetFollowerAbilityDescription(428)
local killtroops=G.GetFollowerAbilityDescription(437)
local killtroopsnodie=killtroops:gsub('%.',' ') .. L['but using troops with just one durability left']
local GARRISON_MISSION_AVAILABILITY2=GARRISON_MISSION_AVAILABILITY .. " %s"
local GARRISON_MISSION_ID="MissionID: %d"
local weak={__mode="v"}
local missionstats=setmetatable({},weak)
local missionmembers=setmetatable({},weak)
local missionthreats=setmetatable({},weak)
local spinners=setmetatable({},weak)
local missionIDS=setmetatable({},weak)
local missionKEYS=setmetatable({},weak)
local function nop() return 0 end
local Current_Sorter
local Second_Sorter
local sortKeys={}
local MAX=999999999
local OHFButtons=OHFMissions.listScroll.buttons
local clean
local displayClean
local function factionLevelColor(level)
level=level or 4
if level < 4 then
return "ORANGE"
elseif level >= MAX_REPUTATION_REACTION then
return "CYAN"
elseif level ==4 then
return "YELLOW"
else
return "GREEN"
end
end
local function getFactionInfoFromCurrency(id)
local factionId=C_CurrencyInfo.GetFactionGrantedByCurrency(id)
if not factionId then return nil,nil end
local faction,_,level=GetFactionInfoByID(factionId)
return faction,level
end
local function GetPerc(mission,realvalue)
local p=addon:GetSelectedParty(mission.missionID,missionKEYS[mission.missionID])
if not p then addon:SetDirtyFlags("FORCED")return 0 end
local perc=p.perc or 0
if realvalue then
return perc
else
return addon:GetBoolean("IGNORELOW") and perc or 1
end
end
local function IsLow(mission)
if addon:IsBlacklisted(mission.missionID) then return "0" end
if addon:GetBoolean("ELITEMODE") and not mission.elite then return "1" end
if addon:GetBoolean("IGNORELOW") then
local p=addon:GetSelectedParty(mission.missionID,missionKEYS[mission.missionID])
if not p or #p==0 then return "2" end
end
return "3"
end
local function IsIgnored(mission)
--return addon:GetBoolean("ELITEMODE") and mission.class=="0"
return addon:GetBoolean("ELITEMODE") and not addon:GetMissionData(mission.missionID,'elite')
end
local sorters={
Garrison_SortMissions_Original=function(mission)
return IsLow(mission)
end,
Garrison_SortMissions_Chance=function(mission)
return IsLow(mission) .. format("%010d",MAX + GetPerc(mission,true))
end,
Garrison_SortMissions_Level=function(mission)
return IsLow(mission) ..format("%010d", (mission.level * 1000 + (mission.iLevel or 0)))
end,
Garrison_SortMissions_Age=function(mission)
return IsLow(mission) .. format("%010d", MAX - mission.offerEndTime)
end,
Garrison_SortMissions_Xp=function(mission)
local p=addon:GetSelectedParty(mission.missionID,missionKEYS[mission.missionID])
return IsLow(mission).. format("%010d",(p.totalXP or 0))
end,
Garrison_SortMissions_HourlyXp=function(mission)
local p=addon:GetSelectedParty(mission.missionID,missionKEYS[mission.missionID])
return IsLow(mission) .. format("%010d", MAX -(-p.totalXP or 0) * 60 / (p.timeseconds or mission.durationSeconds or 36000))
end,
Garrison_SortMissions_Duration=function(mission)
local p=addon:GetSelectedParty(mission.missionID,missionKEYS[mission.missionID])
return IsLow(mission) .. format("%010d",MAX - (p.timeseconds or mission.durationSeconds or 0))
end,
Garrison_SortMissions_Class=function(mission)
local factor=100000
return IsLow(mission) .. format("%010d",MAX -tonumber(format("%7d.%07d",todefault(mission.classOrder,factor), factor - math.min(factor,todefault(mission.classValue,0)))))
end,
}
local function InProgress(mission,frame)
return (mission and mission.inProgress) or OHFMissions.showInProgress or (frame and frame.IsCustom)
end
function module:OnInitialized()
-- Dunno why but every attempt of changing sort starts a memory leak
local sorters={
Garrison_SortMissions_Original=L["Original method"],
Garrison_SortMissions_Chance=L["Success Chance"],
Garrison_SortMissions_Level=L["Level"],
Garrison_SortMissions_Age=L["Expiration Time"],
Garrison_SortMissions_Xp=L["Global approx. xp reward"],
Garrison_SortMissions_HourlyXp=L["Global approx. xp reward per hour"],
Garrison_SortMissions_Duration=L["Duration Time"],
Garrison_SortMissions_Class=L["Reward type"],
}
--@debug@
addon:AddBoolean("ELITEMODE",false,L["Elites mission mode"],L["Only consider elite missions"])
addon:AddBoolean("EXTENDEDTIP",false,L["Extended mission tooltip"],L["Shows a VERY verbose mission toolitpi"])
--@end-debug@
addon:AddSelect("SORTMISSION","Garrison_SortMissions_Original",sorters, L["Sort missions by:"],L["Changes the sort order of missions in Mission panel"])
addon:AddSelect("SORTMISSION2","Garrison_SortMissions_Original",sorters, L["and then by:"],L["Changes the second sort order of missions in Mission panel"])
addon:AddBoolean("IGNORELOW",false,L["Empty missions sorted as last"],L["Empty or 0% success mission are sorted as last. Does not apply to \"original\" method"])
addon:AddBoolean("NOWARN",false,L["Remove no champions warning"],L["Disables warning: "] .. GARRISON_PARTY_NOT_ENOUGH_CHAMPIONS)
addon:AddBoolean("NOBLACKLIST",false,L["Disable blacklisting"],format(L["%s no longer blacklist missions"],KEY_BUTTON2))
addon:RegisterForMenu("mission",
--@debug@
"ELITEMODE",
--@end-debug@
"SORTMISSION",
"SORTMISSION2",
"IGNORELOW",
"NOWARN")
self:LoadButtons()
Current_Sorter=addon:GetString("SORTMISSION")
Second_Sorter=addon:GetString("SORTMISSION2")
self:SecureHookScript(OHF,"OnShow","InitialSetup")
Dialog:Register("BFAUrlCopy", {
text = L["URL Copy"],
width = 500,
editboxes = {
{ width = 484,
on_escape_pressed = function(self, data) self:GetParent():Hide() end,
},
},
on_show = function(self, data)
self.editboxes[1]:SetText(data.url)
self.editboxes[1]:HighlightText()
self.editboxes[1]:SetFocus()
end,
buttons = {
{ text = CLOSE, },
},
show_while_dead = true,
hide_on_escape = true,
})
self:SecureHook("GarrisonMissionButtonRewards_OnEnter")
end
function module:Print(...)
print(...)
end
function module:Events()
addon:RegisterEvent("GARRISON_MISSION_LIST_UPDATE","SetDirtyFlags")
addon:RegisterEvent("GARRISON_MISSION_STARTED","SetDirtyFlags")
addon:RegisterEvent("GARRISON_FOLLOWER_CATEGORIES_UPDATED","SetDirtyFlags")
addon:RegisterEvent("GARRISON_FOLLOWER_ADDED","SetDirtyFlags")
addon:RegisterEvent("GARRISON_FOLLOWER_REMOVED","SetDirtyFlags")
addon:RegisterEvent("GARRISON_FOLLOWER_LIST_UPDATE","SetDirtyFlags")
addon:RegisterEvent("GARRISON_UPDATE","SetDirtyFlags")
addon:RegisterEvent("GARRISON_UPGRADEABLE_RESULT","SetDirtyFlags")
addon:RegisterEvent("GARRISON_MISSION_COMPLETE_RESPONSE","SetDirtyFlags")
addon:RegisterEvent("GARRISON_FOLLOWER_XP_CHANGED","SetDirtyFlags")
addon:RegisterEvent("GARRISON_FOLLOWER_UPGRADED","SetDirtyFlags")
addon:RegisterEvent("GARRISON_FOLLOWER_DURABILITY_CHANGED","SetDirtyFlags")
addon:RegisterEvent("SHIPMENT_CRAFTER_CLOSED","SetDirtyFlags")
end
function module:LoadButtons(...)
local buttonlist=OHFMissions.listScroll.buttons
for i=1,#buttonlist do
local b=buttonlist[i]
self:SecureHookScript(b,"OnEnter","AdjustMissionTooltip")
self:SecureHookScript(b,"OnLeave","SafeAddMembers")
self:RawHookScript(b,"OnClick","RawMissionClick")
b:RegisterForClicks("AnyDown")
local scale=0.8
local f,h,s=b.Title:GetFont()
b.Title:SetFont(f,h*scale,s)
local f,h,s=b.Summary:GetFont()
b.Summary:SetFont(f,h*scale,s)
self:SecureHookScript(b.Rewards[1],"OnMouseUp","PrintLink")
end
end
function addon:SetDirtyFlags(event,missionType,missionID,...)
if event=="GARRISON_MISSION_LIST_UPDATE"
or event=="GARRISON_FOLLOWER_LIST_UPDATE"
or event=="GARRISON_MISSION_STARTED"
or event=="GARRISON_FOLLOWER_UPGRADED"
or event=="GARRISON_FOLLOWER_XP_CHANGED" then
if missionType ~= LE_FOLLOWER_TYPE_GARRISON_8_0 then return end
end
if event=="GARRISON_FOLLOWER_CATEGORIES_UPDATED"
or event=="GARRISON_FOLLOWER_ADDED"
or event=="GARRISON_FOLLOWER_REMOVED"
or event=="GARRISON_FOLLOWER_LIST_UPDATE"
or event=="GARRISON_FOLLOWER_REMOVED"
or event=="GARRISON_FOLLOWER_XP_CHANGED"
or event=="GARRISON_FOLLOWER_UPGRADED"
or event=="GARRISON_FOLLOWER_DURABILITY_CHANGED"
or event=="FORCED"
then
addon:PushRefresher("RefillParties")
addon:PushRefresher("RefreshEquipments")
end
addon:PushRefresher("CleanMissionsCache")
--@debug@
print("Set Dirty state ",event,addon:ListRefreshers())
--@end-debug@
end
local tb={url=""}
local artinfo='*' .. L["Artifact shown value is the base value without considering knowledge multiplier"]
local tipinvocation=0
function module:GarrisonMissionButtonRewards_OnEnter(this)
local tip=GameTooltip
local frame,anchor =tip:GetOwner()
if (frame ~= this) then return end
local lines={}
if (this.currencyID) then
local id,qt=this.currencyID,this.currencyQuantity
local faction,level = getFactionInfoFromCurrency(id)
if not faction then return end
if level then
local levelLabel=_G['FACTION_STANDING_LABEL' .. level]
lines[FACTION_STANDING_CHANGED:format(C(levelLabel,factionLevelColor(level)),C(faction,"GREEN"))]=false
end
for k,v in pairs(lines) do
if (v) then
tip:AddDoubleLine(k,v)
else
tip:AddLine(k,v)
end
end
do
local lines=lines
local numLines=tip:NumLines()
module:SecureHookScript(tip,"OnUpdate",
function(panel)
if panel:NumLines() < numLines then
for k,v in pairs(lines) do
panel:AddDoubleLine(k,v)
end
panel:Show()
end
end
)
module:SecureHookScript(tip,"OnHide",function(panel) module:Unhook(panel,"OnUpdate") module:Unhook(panel,"OnHide") end)
end
end
if this.itemID then
local factionID=addon.allReputationGain[this.itemID]
if factionID then
local faction,_,level=GetFactionInfoByID(factionID)
if level then
level=_G['FACTION_STANDING_LABEL' .. level]
tip:AddLine(FACTION_STANDING_CHANGED:format(C(level,"GREEN"),C(faction,"GREEN")),C.Orange())
end
end
tip:AddLine(safeformat(L["%s for a wowhead link popup"],SHIFT_KEY_TEXT .. KEY_BUTTON1))
end
tip:Show()
--module:Unhook(this,"OnUpdate")
end
function module:PrintLink(this,button)
--@debug@
if (button=="MiddleButton") then
DevTools_Dump(this)
end
--@end-debug@
if this.itemID and ChatEdit_TryInsertChatLink((select(2,GetItemInfo(this.itemID)))) then return end
if button=="RightButton" then
local missionID=this:GetParent().info.missionID
---TODO: Manage rewards blacklisting
--addon:Print("Mission",missionID,addon:GetMissionData(missionID,'class'))
elseif this.itemID and IsShiftKeyDown() then
if Dialog:ActiveDialog("BFAUrlCopy") then
return Dialog:Dismiss("BFAUrlCopy")
else
tb.url="http://www.wowhead.com/item=" ..this.itemID
return Dialog:Spawn("BFAUrlCopy", tb)
end
end
end
--- Full mission panel refresh.
-- Reloads cached mission inProgressMissions and availableMissions.
-- Updates combat ally data
-- Sorts missions
-- Updates top tabs (available/in progress)
-- calls Update
--
function module:OnUpdateMissions(frame)
--@debug@
addon:Print("Called OnUpdateMissions with ",addon:ListRefreshers())
--@end-debug@
if addon:EmptyPermutations() then
addon:PushRefresher("RefillParties")
end
addon:RunRefreshers()
end
function module:OnUpdate(frame)
addon:RedrawMissions()
end
function module:CheckShadow()
if not addon:GetBoolean("NOWARN") and not OHFMissions.showInProgress and not OHFCompleteDialog:IsVisible() and missionNonFilled then
local totChamps,maxChamps=addon:GetTotFollowers('CHAMP_' .. AVAILABLE),addon:GetNumber("MAXCHAMP")
--@debug@
print("Checking shadows for ",maxChamps,totChamps)
--@end-debug@
if totChamps==0 then
self:NoMartiniNoParty(GARRISON_PARTY_NOT_ENOUGH_CHAMPIONS)
elseif maxChamps < 3 then
self:NoMartiniNoParty(safeformat(L['Unable to fill missions, raise "%s"'],L["Max champions"]))
else
self:NoMartiniNoParty(L["Unable to fill missions. Check your switches"])
end
else
self:NoMartiniNoParty()
end
end
function addon:CleanMissionsCache()
missionNonFilled=false
wipe(missionKEYS)
wipe(missionIDS)
end
function addon:CleanPermutations()
return addon:GetFullpermutations(true)
end
function addon:Redraw()
self:ApplySORTMISSION(Current_Sorter)
end
function module:OnSingleUpdate(frame)
if OHFMissions:IsVisible() and not OHFCompleteDialog:IsVisible() and frame.info and frame:IsVisible() then
self:AdjustPosition(frame)
--if frame.info.missionID ~= missionIDS[frame] then
local full= not missionIDS[frame] or missionIDS[frame]~=frame.info.missionID
local blacklisted=addon:IsBlacklisted(frame.info.missionID)
if not blacklisted then -- always do a full refresh and see what happens
self:AdjustMissionButton(frame)
else
self:SafeAddMembers(frame)
end
missionIDS[frame]=frame.info.missionID
local mission=addon:GetMissionData(frame.info.missionID)
if blacklisted then
self:Dim(frame)
else
local rw=frame.Rewards[1]
rw.Icon:SetDesaturated(false)
rw.IconBorder:SetDesaturated(false)
if mission.class and mission.class=="Artifact" then
rw.Quantity:SetText(mission.classValue =="0" and "?" or mission.classValue .. "*")
rw.Quantity:Show()
end
end
end
end
local pcall=pcall
local sort=table.sort
local strcmputf8i=strcmputf8i
local tostring=tostring
local function sortfuncProgress(a,b)
if type(a.timeLeftSeconds) == "number" and type(b.timeLeftSeconds)=="number" then
return a.timeLeftSeconds < b.timeLeftSeconds
else
return strcmputf8i(a.name, b.name) < 0
end
end
local function sortfuncAvailable(a,b)
if sortKeys[a.missionID] ~= sortKeys[b.missionID] then
return tostring(sortKeys[a.missionID]) > tostring(sortKeys[b.missionID])
else
return strcmputf8i(a.name, b.name) < 0
end
end
function module:SortMissions()
--@debug@
addon:Print("Sort called")
--@end-debug@
if not OHF:IsVisible() then return end
--@debug@
addon:Print("Sort executed")
--@end-debug@
if OHFMissions.showInProgress then
sort(OHFMissions.inProgressMissions,sortfuncProgress)
return
end
if Current_Sorter=="Garrison_SortMissions_Original" then return end
local f=sorters[Current_Sorter]
local f2=sorters[Second_Sorter]
for k=#OHFMissions.availableMissions,1,-1 do
local missionID=OHFMissions.availableMissions[k].missionID
local mission=addon:GetMissionData(missionID) -- we need the enriched version
--@debug@
if IsIgnored(mission) then
tremove(OHFMissions.availableMissions,k)
else
--@end-debug@
local rc,result =pcall(f,mission)
local rc2,result2 =pcall(f2,mission)
--@debug@
if not rc then addon:Print(missionID,C(result,"Orange")) end
if not rc2 then addon:Print(missionID,C(result2,"Orange")) end
--@end-debug@
if not rc then result="" end
if not rc2 then result2="" end
sortKeys[missionID]=format("%s|%s",result,result2:sub(2))
--@debug@
sortKeys[missionID]=sortKeys[missionID] .. G.GetMissionName(missionID)
end
--@end-debug@
end
--@debug@
--DevTools_Dump(sortKeys)
--@end-debug@
sort(OHFMissions.availableMissions,sortfuncAvailable)
--@debug@
for i=1,#OHFMissions.availableMissions do
local mission=OHFMissions.availableMissions[i]
addon:Print(sortKeys[mission.missionID],mission.name)
end
--@end-debug@
end
local timer
local suspendApply
function addon:PauseApply(pause)
suspendApply=pause
end
function addon:Apply(flag,value)
if suspendApply then return end
local w=module:GetMenuItem(flag)
addon:PushRefresher("CleanMissionsCache")
if not timer then timer=addon:NewDelayableTimer(function() addon:ReloadMissions() end) end
self:GetTutorialsModule():Refresh()
if IsMouseButtonDown() then
timer:Start(0.5)
else
timer:Start(0)
end
end
function addon:ApplySORTMISSION(value)
Current_Sorter=value
return self:ReloadMissions()
end
function addon:ApplySORTMISSION2(value)
addon:Print("SORTMISSION2")
Second_Sorter=value
return self:ReloadMissions()
end
local PushRefresher,RunRefreshers,ListRefreshers do
local Refreshers={
RefillParties=true,
CleanMissionsCache=true
}
local temp={}
function PushRefresher(refresher,obj)
Refreshers[refresher]=obj or true
end
function RunRefreshers()
if next(Refreshers) and OHF:IsVisible() then
--@debug@
addon:Print("Runrefresher called from",debugstack(3,2,0))
--@end-debug@
else
return
end
for method,obj in pairs(Refreshers) do
if type(obj)=="boolean" then
obj=addon
end
--@debug@
addon:Print("Running refresher",method)
--@end-debug@
if type(obj[method])=="function" then
obj[method](obj)
end
end
wipe(Refreshers)
end
function ListRefreshers()
wipe(temp)
for k,_ in pairs(Refreshers) do
tinsert(temp,k)
end
return unpack(temp)
end
end
function addon:PushRefresher(refresher)
return PushRefresher(refresher)
end
function addon:RunRefreshers()
return RunRefreshers()
end
function addon:ListRefreshers()
return ListRefreshers()
end
function addon:ReloadMissions()
--@debug@
addon:Print("ReloadMissions")
--@end-debug@
local OnMissionPage=OHF.MissionTab.MissionPage:IsVisible()
addon:SortTroop()
if OnMissionPage then addon:GetMissionpageModule():ClearParty() end
addon:RunRefreshers()
if OnMissionPage then
local mission=OHF.MissionTab.MissionPage.info or OHF.MissionTab.MissionPage.missionInfo
--@debug@
addon:Print("Refilling mission page for mission ",mission.missionID)
--@end-debug@
addon:GetMissionpageModule():FillParty(mission.missionID)
else
OHFMissions:UpdateMissions()
end
end
function addon:RedrawMissions()
addon:RunRefreshers()
addon:SortTroop()
for i=1,#OHFButtons do
local frame=OHFButtons[i]
module:OnSingleUpdate(frame)
end
return module:CheckShadow()
end
local function ToggleSet(this,value)
return addon:ToggleSet(this.flag,this.tipo,value)
end
local function ToggleGet(this)
return addon:ToggleGet(this.flag,this.tipo)
end
local function PreToggleSet(this)
return ToggleSet(this,this:GetChecked())
end
local pin
local close
local menu
local button
local function OpenMenu()
addon.db.profile.showmenu=true
button:Hide()
menu:Show()
menu.Tutorial:Show()
end
local function CloseMenu()
addon.db.profile.showmenu=false
button:Show()
menu:Hide()
end
local warner
function module:NoMartiniNoParty(text)
if not warner then
warner=CreateFrame("Frame","BFAWarner",OHFMissions , BackdropTemplateMixin and "BackdropTemplate")
warner.label=warner:CreateFontString(nil,"OVERLAY","GameFontNormalHuge3Outline")
warner.label:SetTextColor(C:Orange())
warner:SetAllPoints()
warner.label:SetHeight(100)
warner.label:SetPoint("CENTER")
warner:SetFrameStrata("TOOLTIP")
addon:SetBackdrop(warner,0,0,0,0.7)
end
local label=warner.label
if text then
label:SetText(text)
warner:Show()
else
warner:Hide()
end
end
local optionlist={}
function module:GetMenuItem(flag)
if flag then return optionlist[flag] end
end
function addon:Pulse(start)
if start then
menu.Pulse:Play()
else
menu.Pulse:Stop()
end
end
local function tutorialTip()
local steps=addon:NeedsTutorial() or ''
return C(steps,"green") .. KEY_BUTTON1 .. L["Resume tutorial"] .. "\n" .. KEY_BUTTON2 .. L["Restart tutorial from beginning"]
end
function module:Menu(flag)
menu=CreateFrame("Frame",nil,OHF,"BFAMenu")
menu:SetPoint("TOPLEFT",OHF,"TOPRIGHT",0,30)
menu:SetPoint("BOTTOMLEFT",OHF,"BOTTOMRIGHT",0,0)
-- menu=CreateFrame("Frame",nil,OHFMissions,"BFAMenu")
-- menu:SetPoint("TOPLEFT",OHFMissionTab,"TOPRIGHT",0,30)
-- menu:SetPoint("BOTTOMLEFT",OHFMissionTab,"BOTTOMRIGHT",0,0)
menu.Title:SetText('BFA ' .. addon.version)
menu.Title:SetTextColor(C:Yellow())
menu.Close:SetScript("OnClick",CloseMenu)
menu.Tutorial:RegisterForClicks("LeftButtonUp","RightButtonUp")
addon:RawHookScript(menu.Tutorial,"OnClick",function(this,button) if button=="LeftButton" then addon:ShowTutorial() else addon:GetTutorialsModule():Home() end end)
menu.Tutorial.tooltip=tutorialTip
button=CreateFrame("Button",nil,OHFMissionTab,"BFAPin")
button.tooltip=L["Show/hide ChampionCommander mission menu"]
button:SetScript("OnClick",OpenMenu)
button:GetNormalTexture():SetRotation(math.rad(270))
button:GetHighlightTexture():SetRotation(math.rad(270))
local previous
local factory=addon:GetFactory()
for _,v in pairs(addon:GetRegisteredForMenu("mission")) do
local flag,icon=strsplit(',',v)
local f=factory:Option(addon,menu,flag,200)
optionlist[flag]=f
if type(f)=="table" and f.GetObjectType then
addon:GetVarInfo(flag).guiHidden=true
if previous then
f:SetPoint("TOPLEFT",previous,"BOTTOMLEFT",0,0)
else
f:SetPoint("TOPLEFT",menu,"TOPLEFT",10,-30)
end
local w=f:GetWidth()+30
if w >menu:GetWidth() then menu:SetWidth(w) end
previous=f
end
end
local f=factory:Button(menu,OPTIONS,L["Customization options (non mission related)"],200)
f:SetObj(addon)
f:SetOnChange("Gui")
f:SetPoint("BOTTOM",0,10)
self.Menu=function() addon:Print("Should not call this again") end
end
local stopper=addon:NewModule("stopper","AceHook-3.0")
function addon:UpdateStop(n)
stopper:UnhookAll()
stopper:RawHookScript(OHFMissionFrameMissions,"OnUpdate",GarrisonMissionListMixin.OnUpdate)
end
function module:OptionsButton()
local level=OHFMissionScroll:GetFrameLevel()+5
local h=-27
local option1=addon:GetFactory():Button(OHFMissionScroll,
L["Quick start first mission"],
L["Launch the first filled mission with at least one locked follower.\nKeep SHIFT pressed to actually launch, a simple click will only print mission name with its followers list"],200)
option1:SetPoint("BOTTOMLEFT",100,h)
option1.obj=module
option1:SetOnChange("RunMission")
local option2=addon:GetFactory():Button(OHFMissionScroll,L["Unlock all"],L["Unlocks all follower and slots at once"])
option2:SetPoint("BOTTOM",0,h)
option2:SetOnChange(function() addon:UnReserve() addon:Unban() addon:RedrawMissions() end)
local option3=addon:GetFactory():Button(OHFMissionScroll,RESET,L["Sets all switches to a very permissive setup. Very similar to 1.4.4"])
option3:SetPoint("BOTTOMRIGHT",-100,h)
option3:SetOnChange(function() addon:Reset() end ) --addon:RefreshMissions() end)
optionlist["BUTTON1"]=option1
optionlist["BUTTON2"]=option2
optionlist["BUTTON3"]=option3
for _,f in pairs(optionlist) do
f:SetFrameLevel(level)
end
end
function module:DisplayMenu()
if OHF.MapTab:IsVisible() then
if OHF.TroopsStatusInfo then OHF.TroopsStatusInfo:Hide() end
if OHF.ChampionsStatusInfo then OHF.ChampionsStatusInfo:Hide() end
if menu then menu:Hide() end
else
if OHF.TroopsStatusInfo then OHF.TroopsStatusInfo:Show() end
if OHF.ChampionsStatusInfo then OHF.ChampionsStatusInfo:Show() end
if addon.db.profile.showmenu then OpenMenu() else CloseMenu() end
end
end
function module:InitialSetup(this)
if not OHF:ShouldShowMissionsAndFollowersTabs() then return end
collectgarbage("stop")
if type(addon.db.global.warn01_seen)~="number" then addon.db.global.warn01_seen =0 end
if type(addon.db.global.warn02_seen)~="number" then addon.db.global.warn02_seen =0 end
self:Menu()
self:Unhook(this,"OnShow")
self:SecureHookScript(this,"OnShow","MainOnShow")
self:SecureHookScript(this,"OnHide","MainOnHide")
OHF.ChampionsStatusInfo=OHF.GarrCorners:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
OHF.ChampionsStatusInfo:SetPoint("TOPRIGHT",-45,-2)
OHF.ChampionsStatusInfo:SetText("")
OHF.TroopsStatusInfo=OHF.GarrCorners:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
OHF.TroopsStatusInfo:SetPoint("TOPLEFT",80,-2)
OHF.TroopsStatusInfo:SetText("")
self:OptionsButton()
self:EvOn()
self:MainOnShow()
addon:ReloadMissions()
-- For some strange reason, we need this to avoid leaking memory
addon:UpdateStop()
collectgarbage("restart")
addon:MarkAsNew(OHF,addon:NumericVersion(),safeformat(L["%s, please review the tutorial\n(Click the icon to dismiss this message and start the tutorial)"],me .. ' ' .. addon.version),"ShowTutorial")
--@alpha@
--addon.version="1.6.0 Alpha"
--@end-alpha@
local _,_,versiontype=addon.version:find("(Beta)")
if not versiontype then _,_,versiontype=addon.version:find("(Alpha)") end
if versiontype then
local frame=CreateFrame("Frame",nil,OHF,"TooltipBorderedFrameTemplate")
frame.label=frame:CreateFontString(nil,"OVERLAY","GameFontNormalHuge")
frame:SetFrameStrata("TOOLTIP")
frame.label:SetAllPoints(frame)
frame:SetPoint("BOTTOM",OHF,"TOP",0,30)
frame.label:SetWidth(OHF:GetWidth()-10)
frame.label:SetText("You are using |cffff0000BETA VERSION|r "..addon.version ..".\nIf something doesnt work usually typing /reload will fix it.")
if versiontype=="Alpha" then
frame.label:SetText("You are using |cffff0000ALFA VERSION|r "..addon.version ..".\nIf something doesnt work usually typing /reload will fix it.")
else
frame.label:SetText("You are using |cffff0000BETA VERSION|r "..addon.version ..".\nIf something doesnt work usually typing /reload will fix it.")
end
frame.label:SetJustifyV("CENTER")
frame.label:SetJustifyH("CENTER")
frame:SetHeight(frame.label:GetStringHeight()+15)
frame:SetWidth(OHF:GetWidth())
frame.label:SetPoint("CENTER")
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart",function(frame) if addon:GetBoolean('MOVEPANEL') then OHF:StartMoving() end end)
frame:SetScript("OnDragStop",function(frame) OHF:StopMovingOrSizing() end)
end
if addon:NeedsTutorial() then
addon:Pulse(true)
addon:ScheduleTimer("Pulse",5)
end
end
function addon:ShowTutorial()
OpenMenu()
addon:GetTutorialsModule():Show(true)
end
function addon:Reset()
addon:PauseApply(true)
local w=module:GetMenuItem("BASECHANCE")
if w then w:SetValue(0) end
w=module:GetMenuItem("BONUSCHANCE")
if w then w:SetValue(100) end
w=module:GetMenuItem("IGNOREBUSY")
if w then w:SetValue(true) end
w=module:GetMenuItem("IGNOREINACTIVE")
if w then w:SetValue(true) end
for _,k in ipairs{'NEVERKILLTROOPS','SAVETROOPS','MAXIMIZEXP', "NOTROOPS", "BONUS", "SPARE", "MAKEITQUICK", "MAKEITVERYQUICK"} do
w=module:GetMenuItem(k)
if w then w:SetValue(false) end
end
addon:PauseApply(false)
addon:Apply()
end
function addon:GetMissionKey(missionID)
return missionID and missionKEYS[missionID] or missionKEYS
end
function addon:GetMembersFrame(frame)
return missionmembers[frame]
end
function module:RunMission()
return addon:GetAutopilotModule():RunMission()
end
function module:SelectTab(table,id)
print("SELECT",id)
self:DisplayMenu()
end
function module:EvOn()
for _,m in addon:IterateModules() do
if m.Events then m:Events() end
end
--self:RawHook(OHFMissions,"Update","OnUpdate",true)
self:SecureHook("Garrison_SortMissions","SortMissions")
self:Hook(OHFMissions,"UpdateMissions","OnUpdateMissions",true)
self:SecureHook(OHFMissions,"Update","OnUpdate") --self:RawHook(OHFMissions,"Update","OnUpdate",true)
self:SecureHook(OHF,"SelectTab")
end
function module:EvOff()
for _,m in addon:IterateModules() do
if m.EventsOff then
m:EventsOff()
elseif m.UnregisterAllEvents then
m:UnregisterAllEvents()
end
end
self:Unhook("Garrison_SortMissions")
self:Unhook(OHFMissions,"UpdateMissions")
self:Unhook(OHFMissions,"Update")
self:UnHook(OHF,"SelectTab")
end
function module:MainOnShow()
print("OnShow")
self:DisplayMenu()
addon:GetResources(true)
--self:Unhook(OHFMissions,"Update")
addon:RefreshFollowerStatus()
addon:GetCacheModule():GARRISON_LANDINGPAGE_SHIPMENTS()
addon:ParseFollowers()
addon.lastChange=GetTime()
--module:SortMissions()
OHF:SelectTab(OHF.selectedTab)
end
function module:MainOnHide()
collectgarbage()
addon:GetAutocompleteModule():AutoClose()
addon:GetTutorialsModule():Hide()
end
function module:AdjustPosition(frame)
local mission=frame.info
frame.Title:ClearAllPoints()
if mission.isResult then
frame.Title:SetPoint("TOPLEFT",165,15)
elseif mission.inProgress then
frame.Title:SetPoint("TOPLEFT",165,-10)
else
frame.Title:SetPoint("TOPLEFT",165,-7)
end
if mission.isRare then
frame.Title:SetTextColor(frame.RareText:GetTextColor())
else
frame.Title:SetTextColor(C:White())
end
frame.RareText:Hide()
-- Compacting mission time and level
frame.RareText:Hide()
frame.Level:ClearAllPoints()
frame.MissionType:ClearAllPoints()
frame.ItemLevel:Hide()
frame.Level:SetPoint("LEFT",5,0)
frame.MissionType:SetPoint("LEFT",5,0)
if mission.isMaxLevel then
frame.Level:SetText(mission.iLevel)
else
frame.Level:SetText(mission.level)
end
local missionID=mission.missionID
end
function module:AdjustMissionButton(frame)
if not OHF:IsVisible() then return end
local mission=frame.info
local missionID=mission and mission.missionID
if not missionID then return end
missionIDS[frame]=missionID
-- Adding stats frame (expiration date and chance)
if not missionstats[frame] then
missionstats[frame]=CreateFrame("Frame",nil,frame,"BFAStats")
--@debug@
self:RawHookScript(missionstats[frame],"OnEnter","MissionTip")
--@end-debug@
end
if not missionmembers[frame] then
missionmembers[frame]=CreateFrame("Frame",nil,frame,"BFAMembers")
end
if not missionthreats[frame] then
missionthreats[frame]=CreateFrame("Frame",nil,frame,"BFAThreats")
end
local stats=missionstats[frame]
local aLevel,aIlevel=addon:GetAverageLevels()
if mission.isMaxLevel then
frame.Level:SetText(mission.iLevel)
frame.Level:SetTextColor(addon:GetDifficultyColors(math.floor((aIlevel-750)/(mission.iLevel-750)*100)))
else
frame.Level:SetText(mission.level)
frame.Level:SetTextColor(addon:GetDifficultyColors(math.floor(aLevel/mission.level*100)))
end
if mission.inProgress then
stats:SetPoint("LEFT",48,14)
stats.Expire:Hide()
else
stats.Expire:SetFormattedText("%s\n%s",GARRISON_MISSION_AVAILABILITY,mission.offerTimeRemaining)
stats.Expire:SetTextColor(addon:GetAgeColor(mission.offerEndTime))
stats:SetPoint("LEFT",48,0)
stats.Expire:Show()
end
stats.Chance:Show()
if addon:IsBlacklisted(missionID) then
return
end
self:SafeAddMembers(frame)
for i=1,#frame.Rewards do
local reward=frame.Rewards[i]
if (reward.currencyID) then
local id,qt=reward.currencyID,reward.currencyQuantity
reward.Quantity:SetText(qt)