forked from alarofrunetotem/OrderHallCommander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.lua
440 lines (426 loc) · 13.7 KB
/
core.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
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('Core',"AceHook-3.0","AceEvent-3.0","AceTimer-3.0") --#Module
function addon:GetCoreModule() 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=OrderHallMissionFrame
local OHFMissionTab=OrderHallMissionFrame.MissionTab --Container for mission list and single mission
local OHFMissions=OrderHallMissionFrame.MissionTab.MissionList -- same as OrderHallMissionFrameMissions Call Update on this to refresh Mission Listing
local OHFFollowerTab=OrderHallMissionFrame.FollowerTab -- Contains model view
local OHFFollowerList=OrderHallMissionFrame.FollowerList -- Contains follower list (visible in both follower and mission mode)
local OHFFollowers=OrderHallMissionFrameFollowers -- Contains scroll list
local OHFMissionPage=OrderHallMissionFrame.MissionTab.MissionPage -- Contains mission description and party setup
local OHFMapTab=OrderHallMissionFrame.MapTab -- Contains quest map
local OHFCompleteDialog=OrderHallMissionFrameMissions.CompleteDialog
local OHFMissionScroll=OrderHallMissionFrameMissionsListScrollFrame
local OHFMissionScrollChild=OrderHallMissionFrameMissionsListScrollFrameScrollChild
local LE_FOLLOWER_TYPE_GARRISON_6_0=Enum.GarrisonFollowerType.FollowerType_6_0
local LE_FOLLOWER_TYPE_SHIPYARD_6_2=Enum.GarrisonFollowerType.FollowerType_6_2
local LE_FOLLOWER_TYPE_GARRISON_7_0=Enum.GarrisonFollowerType.FollowerType_7_0
local LE_FOLLOWER_TYPE_GARRISON_8_0=Enum.GarrisonFollowerType.FollowerType_8_0
local LE_GARRISON_TYPE_6_0=Enum.GarrisonType.Type_6_0
local LE_GARRISON_TYPE_6_2=Enum.GarrisonType.Type_6_2
local LE_GARRISON_TYPE_7_0=Enum.GarrisonType.Type_7_0
local LE_GARRISON_TYPE_8_0=Enum.GarrisonType.Type_8_0
local followerType=LE_FOLLOWER_TYPE_GARRISON_7_0
local garrisonType=LE_GARRISON_TYPE_7_0
local FAKE_FOLLOWERID="0x0000000000000000"
local MAX_LEVEL=110
local ShowTT=OrderHallCommanderMixin.ShowTT
local HideTT=OrderHallCommanderMixin.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 missionPanelMissionList=OrderHallMissionFrameMissions
--[[
Su OrderHallMissionFrameMissions viene chiamato Update() per aggiornare le missioni
.listScroll = padre della scrolllist delle missioni
<code>
local scrollFrame = self.listScroll;
local offset = HybridScrollFrame_GetOffset(scrollFrame);
</code>
--]]
--[[
OHC- OrderHallMissionFrame.FollowerTab.DurabilityFrame : OnShow : table: 0000000033557BD0
OHC- OrderHallMissionFrame.FollowerTab.QualityFrame : OnShow : table: 0000000033557C20
OHC- OrderHallMissionFrame.FollowerTab.PortraitFrame : OnShow : table: 0000000033557D60
OHC- OrderHallMissionFrame.FollowerTab.ModelCluster : OnShow : table: 0000000033557F40
OHC- OrderHallMissionFrame.FollowerTab.XPBar : OnShow : table: 00000000335585D0
--]]
-- Upvalued functions
local GetItemInfo=GetItemInfo
--if I then GetItemInfo=I:GetCachingGetItemInfo() end
local tostring=tostring
local tostringall=tostringall
local strjoin=strjoin
local select,CreateFrame,pairs,type,todefault,math=select,CreateFrame,pairs,type,todefault,math
local QuestDifficultyColors,GameTooltip=QuestDifficultyColors,GameTooltip
local tinsert,tremove,tContains=tinsert,tremove,tContains
local format=format
local resolve=addon.resolve
local colors=addon.colors
local menu
local menuType="OHCMenu"
local menuOptions={mission={},follower={}}
local _G=_G
function addon:ApplyMOVEPANEL(value)
OHF:EnableMouse(value)
OHF:SetMovable(value)
end
function addon:OnInitialized()
_G.dbOHCperChar=_G.dbOHCperChar or {}
if type(self.db.global.tutorialStep)~="number" then
self.db.global.tutorialStep=1
end
menu=CreateFrame("Frame")
--@debug@
--[[
local f=menu
f:RegisterAllEvents()
self:RawHookScript(f,"OnEvent","ShowGarrisonEvents")
]]--
--@end-debug@
self:AddLabel(L["General"])
self:AddBoolean("MOVEPANEL",true,L["Make Order Hall Mission Panel movable"],L["Position is not saved on logout"])
self:AddBoolean("TROOPALERT",true,L["Troop ready alert"],L["Notifies you when you have troops ready to be collected"])
self:AddBoolean("QUICKSTART",nil,L["Unsafe mission start"],safeformat(L["Only need %s instead of %s to start a mission from mission list"],SHIFT_KEY_TEXT,CTRL_SHIFT_KEY_TEXT))
self:loadHelp()
OHF:RegisterForDrag("LeftButton")
OHF:SetScript("OnDragStart",function(frame) if self:GetBoolean('MOVEPANEL') then frame:StartMoving() end end)
OHF:SetScript("OnDragStop",function(frame) frame:StopMovingOrSizing() end)
self:ApplyMOVEPANEL(self:GetBoolean('MOVEPANEL'))
end
function addon:IsBlacklisted(missionID)
return self.db.profile.blacklist[missionID]
end
function addon:ClearMenu()
if menu.widget then
pcall(AceGUI.Release,AceGUI,menu.widget)
menu.widget=nil
end
menu:Hide()
end
function addon:RegisterForMenu(menu,...)
for i=1,select('#',...) do
local value=(select(i,...))
if type(value)=="table" then
if type(value.arg)=="string" then
value=value.arg
elseif type(value['function'])=="string" then
value=value['function']
else
value=false
end
end
if value and not tContains(menuOptions[menu],value) then
tinsert(menuOptions[menu],value)
end
end
end
function addon:GetRegisteredForMenu(menu)
return menuOptions[menu]
end
do
end
function addon:ActivateButton(button,OnClick,Tooltiptext,persistent)
button:SetScript("OnClick",function(...) self[OnClick](self,...) end )
if (Tooltiptext) then
button.tooltip=Tooltiptext
button:SetScript("OnEnter",ShowTT)
button:SetScript("OnLeave",HideTT)
else
button:SetScript("OnEnter",nil)
button:SetScript("OnLeave",nil)
end
end
--- Helpers
--
function addon:SetBackdrop(frame,r,g,b,a)
r=r or 1
g=g or 0
b=b or 0
a=a or 1
frame:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
xedgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4}
}
)
frame:SetBackdropColor(r,g,b,a)
end
function addon:GetDifficultyColors(...)
local q=self:GetDifficultyColor(...)
return q.r,q.g,q.b
end
function addon:GetDifficultyColor(perc,usePurple)
if perc>=100 then
return C.Green
elseif(perc >90) then
return QuestDifficultyColors['standard']
elseif (perc >74) then
return QuestDifficultyColors['difficult']
elseif(perc>49) then
return QuestDifficultyColors['verydifficult']
elseif(perc >20) then
return QuestDifficultyColors['impossible']
else
return not usePurple and C.Silver or C.Epic
end
end
function addon:GetAgeColor(age)
age=todefault(age,0)
if age>GetTime() then age=age-GetTime() end
if age < 0 then age=0 end
local hours=floor(age/3600)
local q=self:GetDifficultyColor(hours+20,true)
return q.r,q.g,q.b
end
local function tContains(table, item)
local index = 1;
while table[index] do
if ( item == table[index] ) then
return index;
end
index = index + 1;
end
return nil;
end
local newsframes={}
function addon:MarkAsNew(obj,key,message,method)
local db=self.db.global
if not db.news then db.news={} end
--@debug@
db.news[key]=true
--@end-debug@
if (not db.news[key]) then
local f=CreateFrame("Button",nil,obj,"OHCWhatsNew")
f.tooltip=message
f.texture:ClearAllPoints()
f.texture:SetAllPoints()
f:GetHighlightTexture():ClearAllPoints()
f:GetHighlightTexture():SetAllPoints()
f:SetPoint("TOPLEFT",obj,"TOPLEFT",0,0)
f:SetFrameStrata("TOOLTIP")
f:Show()
if method then
f:SetScript("OnClick",function(frame) self[method](self,frame) self:MarkAsSeen(key) end)
else
f:SetScript("OnClick",function(frame) self:MarkAsSeen(key) end)
end
newsframes[key]=f
return true
end
end
function addon:MarkAsSeen(key)
local db=self.db.global
if not db.news then db.news={} end
db.news[key]=true
if newsframes[key] then newsframes[key]:Hide() end
end
--@do-not-package@
local gamu=GetAddOnMemoryUsage
local uamu=UpdateAddOnMemoryUsage
local redpattern="c|FFFF0000%dM|r"
local greenpattern="%dM"
local function wrap(obj,func)
addon:Print("Hook func",func)
local old=obj[func]
obj[func] = function(...)
local r1,r2,r3,r4,r5,r6,r7,r8,r9=old(...)
local m2=gamu(me)
addon:Print("Called",func,format(greenpattern,m2/1024))
return r1,r2,r3,r4,r5,r6,r7,r8,r9
end
end
local profile={}
local min=5
function addon:LoadProfileData(obj,objname)
for name,func in pairs(obj) do
if type(func)=="function" then
local total,times=GetFunctionCPUUsage(func,true)
if times >= min then
local average=total/(times>0 and times or 1)
profile[format("%06d.%s:%s",999999-average*1000,objname,name)]={total=total,times=times,average=average}
end
end
end
end
function addon:ProfileStats(newmin)
if newmin then min = newmin end
wipe(profile)
local profiling=GetCVarBool("scriptProfile")
if not profiling then
SetCVar("scriptProfile",true)
ReloadUI()
end
for name,module in self:IterateModules() do
self:LoadProfileData(module,name)
if module.ProfileStats then
module:ProfileStats()
end
end
self:LoadProfileData(self,"MAIN")
if ViragDevTool_AddData then
ViragDevTool_AddData(profile,"OHC_PROFILE")
end
end
function addon:Resolve(frame)
local name
if type(frame)=="table" and frame.GetName then
name=frame:GetName()
if not name then
local parent=frame:GetParent()
if not parent then return "UIParent" end
for k,v in pairs(parent) do
if v==frame then
name=self:Resolve(parent) .. '.'..k
return name
end
end
return tostring(frame)
else
return name
end
end
return "unk"
end
local events=CreateFrame("Frame")
addon.evt=setmetatable({},{__index=function(t,v) return 0 end})
addon.evtCount=setmetatable({},{__index=function(t,v) return 0 end})
events:RegisterAllEvents()
events:SetScript("OnEvent",
function(this,event,...)
if event:find("GARRISON") then
addon.evtCount[event]=addon.evtCount[event] +1
local signature=strjoin(' , ',event,tostringall(...))
addon.evt[signature]=addon.evt[signature] +1
end
end
)
function addon:GetScroller(title,type,h,w)
h=h or 800
w=w or 400
type=type or "Frame"
local scrollerWindow=AceGUI:Create("Frame")
--scrollerWindow.frame:SetAlpha(1)
scrollerWindow:SetTitle(title)
scrollerWindow:SetLayout("Fill")
--local scrollcontainer = AceGUI:Create("SimpleGroup") -- "InlineGroup" is also good
--scrollcontainer:SetFullWidth(true)
--scrollcontainer:SetFullHeight(true) -- probably?
--scrollcontainer:SetLayout("Fill") -- important!
--scrollerWindow:AddChild(scrollcontainer)
local scroll = AceGUI:Create("ScrollFrame")
scroll:SetLayout("Flow") -- probably?
scroll:SetFullWidth(true)
scroll:SetFullHeight(true)
scrollerWindow:AddChild(scroll)
scrollerWindow:SetCallback("OnClose","Release")
scrollerWindow:SetHeight(h)
scrollerWindow:SetWidth(w)
scrollerWindow:SetPoint("CENTER")
scrollerWindow:Show()
scroll.addRow=scroll.AddRow
return scroll
end
function addon:cutePrint(scroll,level,k,v)
if (type(level)=="table") then
for k,v in kpairs(level,safesort) do
self:cutePrint(scroll,"",k,v)
end
return
end
if (type(v)=="table") then
if (level:len()>6) then return end
self:AddRow(scroll,level..C(k,"Azure")..":" ..C("Table","Orange") .. " " .. tostring(#v))
for kk,vv in pairs(v) do
self:cutePrint(scroll,level .. " ",kk,vv)
end
else
if (type(v)=="string" and v:sub(1,2)=='0x') then
v=v.. " " ..tostring(self:GetFollowerData(v,'name'))
end
self:AddRow(scroll,level..C(k,"White")..":" ..C(v,"Yellow"))
end
end
function addon:Dump(title,data)
if type(data)=="string" then
data=_G[data]
end
if type(data) ~= "table" then
print(data,"is not a table")
return
end
local scroll=self:GetScroller(title)
print("Dumping",title)
self:cutePrint(scroll,data)
return scroll
end
--@end-do-not-package@
if not _G.OHC then
_G.OHC=addon
end