forked from alarofrunetotem/GarrisonCommander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Widgets.lua
507 lines (499 loc) · 14.4 KB
/
Widgets.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
local me, ns = ...
ns.Configure()
local addon=addon
local _G=_G
local wipe=wipe
local format=format
local UNKNOWN=UNKNOWN
local LE_FOLLOWER_TYPE_GARRISON_6_0=LE_FOLLOWER_TYPE_GARRISON_6_0
local LE_FOLLOWER_TYPE_SHIPYARD_6_2=LE_FOLLOWER_TYPE_SHIPYARD_6_2
local module=addon:NewSubModule("Widgets") --#module
local function Constructor()
local widget= AceGUI:Create("Label")
widget.SetAtlas=function (atlasname)
widget.image:SetAtlas(atlasname)
end
widget.OnRelease=function() widget.image:SetAtlas(nil) end
end
AceGUI:RegisterWidgetType("AtlasLabel", Constructor, 1)
--- Quick backdrop
--
local backdrop = {
bgFile="Interface\\TutorialFrame\\TutorialFrameBackground",
edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",
tile=true,
tileSize=16,
edgeSize=16,
insets={bottom=7,left=7,right=7,top=7}
}
local function addBackdrop(f,color)
f:SetBackdrop(backdrop)
f:SetBackdropBorderColor(C[color or 'Yellow']())
end
local function GMCList()
local Type="GCMCList"
local Version=1
local m={} --#GMCList
function m:ScrollDown()
local obj=self.scroll
if (#self.missions >1 and obj.scrollbar and obj.scrollbar:IsShown()) then
obj:SetScroll(80)
obj.scrollbar.ScrollDownButton:Click()
end
end
function m:OnAcquire()
wipe(self.missions)
end
function m:Show()
self.frame:Show()
end
function m:Hide()
self.frame:Hide()
self:Release()
end
function m:AddButton(text,action)
local obj=self.scroll
local b=AceGUI:Create("Label")
b:SetFullWidth(true)
b:SetText(text)
b:SetColor(C.yellow.r,C.yellow.g,C.yellow.b)
--b:SetCallback("OnClick",action)
obj:AddChild(b)
end
function m:AddMissionButton(mission,party,perc,source)
if not self.missions[mission.missionID] then
local obj=self.scroll
local b=AceGUI:Create("GMCSlimMissionButton")
b:SetMission(mission,party,perc,source)
b:SetScale(0.7)
b:SetFullWidth(true)
self.missions[mission.missionID]=b
obj:AddChild(b)
b.frame.Success:Hide()
b.frame.Failure:Hide()
b.frame.Spinner:Show()
b.frame.Spinner.Anim:Play()
end
end
function m:AddMissionResult(missionID,success)
local mission=self.missions[missionID]
if mission then
local frame=mission.frame
frame.Spinner.Anim:Stop()
frame.Spinner:Hide()
if success then
frame.Success:Show()
frame.Failure:Hide()
for i=1,#frame.Rewards do
frame.Rewards[i].Icon:SetDesaturated(false)
end
else
frame.Success:Hide()
frame.Failure:Show()
for i=1,#frame.Rewards do
frame.Rewards[i].Icon:SetDesaturated(true)
frame.Rewards[i].Quantity:Hide()
end
end
end
end
function m:AddRow(data,...)
local obj=self.scroll
local l=AceGUI:Create("InteractiveLabel")
l:SetFontObject(GameFontNormalSmall)
l:SetText(data)
l:SetColor(...)
l:SetFullWidth(true)
obj:AddChild(l)
end
function m:AddFollower(follower,xp,levelup)
--@debug@
print(follower)
--@end-debug@
local followerID=follower.followerID
local followerType=follower.followerTypeID
if xp < 0 then
return self:AddFollowerIcon(followerType,addon:GetFollowerTexture(follower),
format("%s was destroyed",follower.fullname or L["A ship"]))
end
if follower.maxed and not levelup then
return
-- return self:AddFollowerIcon(followerType,addon:GetFollowerTexture(follower),format("%s is already at maximum xp",follower.fullname))
end
local quality=G.GetFollowerQuality(followerID) or follower.quality
local level=G.GetFollowerLevel(followerID) or follower.level
if levelup then
PlaySound(SOUNDKIT.UI_GARRISON_COMMAND_TABLE_FOLLOWER_LEVEL_UP);
end
return self:AddFollowerIcon(followerType,
addon:GetFollowerTexture(follower),
format("%s gained %d xp%s%s",
follower.fullname,
xp,
levelup and " |cffffed1a*** Level Up ***|r ." or ".",
format(" %d to go.",follower.levelXP-follower.xp))
)
end
function m:AddFollowerIcon(followerType,icon,text)
local l=self:AddIconText(icon,text)
if followerType==LE_FOLLOWER_TYPE_SHIPYARD_6_2 then
if toc<70000 then
local left,right,top,bottom
left=0
right=0.6
top=0
bottom=0.5
l:SetImage(icon,left,right,top,bottom)
end
l:SetImageSize(36,36)
l:SetHeight(38)
end
end
function m:AddIconText(icon,text,qt)
local obj=self.scroll
local l=AceGUI:Create("Label")
l:SetFontObject(GameFontNormalSmall)
if (qt) then
l:SetText(format("%s x %s",text,qt))
else
l:SetText(text)
end
l:SetImage(icon)
l:SetImageSize(24,24)
l:SetHeight(26)
l:SetFullWidth(true)
obj:AddChild(l)
if (obj.scrollbar and obj.scrollbar:IsShown()) then
obj:SetScroll(80)
obj.scrollbar.ScrollDownButton:Click()
end
return l
end
function m:AddItem(itemID,qt)
local obj=self.scroll
local _,itemlink,itemquality,_,_,_,_,_,_,itemtexture=GetItemInfo(itemID)
if not itemlink then
self:AddIconText(itemtexture,itemID,qt)
else
self:AddIconText(itemtexture,itemlink,qt)
end
end
---@function [parent=#GMCList]
local function Constructor()
local widget=AceGUI:Create("GMCGUIContainer")
widget:SetLayout("Fill")
widget.missions={}
local scroll = AceGUI:Create("ScrollFrame")
scroll:SetLayout("List") -- probably?
scroll:SetFullWidth(true)
scroll:SetFullHeight(true)
widget:AddChild(scroll)
for k,v in pairs(m) do widget[k]=v end
widget:Show()
widget.scroll=scroll
return widget
end
AceGUI:RegisterWidgetType(Type,Constructor,Version)
end
local function GMCGUIContainer()
local Type="GMCGUIContainer"
local Version=1
local m={} --#GMCGUIContainer
function m:Close()
self.frame.CloseButton:Click()
end
function m:OnAcquire()
self.frame:EnableMouse(true)
self:SetTitleColor(C.Yellow())
self.frame:SetFrameStrata("HIGH")
self.frame:SetFrameLevel(999)
end
function m:SetContentWidth(x)
self.content:SetWidth(x)
end
---@function [parent=#GMCGUIContainer]
local function Constructor()
local frame=CreateFrame("Frame",Type..(GetTime()*1000),nil,"GarrisonUITemplate")
for _,f in pairs({frame:GetRegions()}) do
if (f:GetObjectType()=="Texture" and f:GetAtlas()=="Garr_WoodFrameCorner") then f:Hide() end
end
local widget={frame=frame,missions={}}
widget.type=Type
widget.SetTitle=function(self,...) self.frame.TitleText:SetText(...) end
widget.SetTitleColor=function(self,...) self.frame.TitleText:SetTextColor(...) end
for k,v in pairs(m) do widget[k]=v end
frame:SetScript("OnHide",function(self) self.obj:Fire('OnClose') end)
frame.obj=widget
--Container Support
local content = CreateFrame("Frame",nil,frame)
widget.content = content
--addBackdrop(content,'Green')
content.obj = widget
content:SetPoint("TOPLEFT",25,-25)
content:SetPoint("BOTTOMRIGHT",-25,25)
AceGUI:RegisterAsContainer(widget)
return widget
end
AceGUI:RegisterWidgetType(Type,Constructor,Version)
end
local function GMCLayer()
local Type="GMCLayer"
local Version=1
local function OnRelease(self)
wipe(self.childs)
end
local m={} --#GMCLayer
function m:OnAcquire()
self.frame:SetParent(UIParent)
self.frame:SetFrameStrata("HIGH")
self.frame:SetHeight(50)
self.frame:SetWidth(100)
self.frame:Show()
self.frame:SetPoint("LEFT")
end
function m:Show()
return self.frame:Show()
end
function m:Hide()
self.frame:Hide()
self:Release()
end
function m:SetScript(...)
return self.frame:SetScript(...)
end
function m:SetParent(...)
return self.frame:SetParent(...)
end
function m:PushChild(child,index)
self.childs[index]=child
self.scroll:AddChild(child)
end
function m:RemoveChild(index)
local child=self.childs[index]
if (child) then
self.childs[index]=nil
child:Hide()
self:DoLayout()
end
end
function m:ClearChildren()
wipe(self.childs)
self:AddScroll()
end
function m:AddScroll()
if (self.scroll) then
self:ReleaseChildren()
self.scroll=nil
end
local scroll = AceGUI:Create("ScrollFrame")
scroll:SetLayout("List")
scroll:SetFullWidth(true)
scroll:SetFullHeight(true)
self:AddChild(scroll)
self.scroll = scroll
end
---@function [parent=#GMCLayer]
local function Constructor()
local frame=CreateFrame("Frame",nil,nil,"BackdropTemplate")
local title=frame:CreateFontString(nil, "BACKGROUND", "GameFontNormalHugeBlack")
title:SetJustifyH("CENTER")
title:SetJustifyV("CENTER")
title:SetPoint("TOPLEFT")
title:SetPoint("TOPRIGHT")
title:SetHeight(0)
title:SetWidth(0)
addBackdrop(frame)
local widget={childs={}}
widget.title=title
widget.type=Type
widget.SetTitle=function(self,...) self.title:SetText(...) end
widget.SetTitleColor=function(self,...) self.title:SetTextColor(...) end
widget.SetFormattedTitle=function(self,...) self.title:SetFormattedText(...) end
widget.SetTitleWidth=function(self,...) self.title:SetWidth(...) end
widget.SetTitleHeight=function(self,...) self.title:SetHeight(...) end
widget.frame=frame
frame.obj=widget
for k,v in pairs(m) do widget[k]=v end
frame:SetScript("OnHide",function(self) self.obj:Fire('OnClose') end)
--Container Support
local content = CreateFrame("Frame",nil,frame)
widget.content = content
content.obj = self
content:SetPoint("TOPLEFT",title,"BOTTOMLEFT",6,0)
content:SetPoint("TOPRIGHT",title,"BOTTOMRIGHT",-6,0)
content:SetPoint("BOTTOM",0,6)
AceGUI:RegisterAsContainer(widget)
return widget
end
AceGUI:RegisterWidgetType(Type,Constructor,Version)
end
local function GMCMissionButton()
local Type1="GMCMissionButton"
local Type2="GMCSlimMissionButton"
local Version=1
local unique=0
local function GarrisonMissionButton_OnEnter(...)
addon:ScriptGarrisonMissionButton_OnEnter(...)
end
local m={} --#GMCMissionButton
function m:OnAcquire()
local frame=self.frame
frame.info=nil
frame:SetHeight(self.type==Type1 and 80 or 80)
frame:SetAlpha(1)
frame:SetScale(1.0)
frame:Enable()
frame.Overlay:Hide()
frame.Overlay.Overlay:SetAlpha(.4)
for i=1,#self.scripts do
frame:SetScript(self.scripts[i],nil)
end
for i=1,#frame.Rewards do
frame.Rewards[i].Icon:SetDesaturated(false)
end
wipe(self.scripts)
return
end
function m:Show()
return self.frame:Show()
end
function m:SetHeight(h)
return self.frame:SetHeight(h)
end
function m:Hide()
self.frame:SetHeight(1)
self.frame:SetAlpha(0)
return self.frame:Disable()
end
function m:SetScript(name,method)
tinsert(self.scripts,name)
return self.frame:SetScript(name,method)
end
function m:SetScale(s)
return self.frame:SetScale(s)
end
function m:Blacklist(blacklisted)
local mb=self.frame
if blacklisted then
--@debug@
print("Blacklisting",mb:GetName())
--@end-debug@
mb.Overlay:Show()
mb.Overlay.Overlay:SetAlpha(1)
for i,v in pairs(mb.gcPANEL.Party) do
v.PortraitFrame.Portrait:SetDesaturated(true)
v.PortraitFrame.PortraitRingQuality:Hide()
v.PortraitFrame.LevelBorder:Hide()
end
for i,v in pairs(mb.Rewards) do
v.Icon:SetDesaturated(true)
v.Quantity:Hide()
end
return true
else
mb.Overlay:Hide()
mb.Overlay.Overlay:SetAlpha(0.4)
for i,v in pairs(mb.gcPANEL.Party) do
v.PortraitFrame.Portrait:SetDesaturated(false)
v.PortraitFrame.PortraitRingQuality:Show()
v.PortraitFrame.LevelBorder:Show()
end
for i,v in pairs(mb.Rewards) do
v.Icon:SetDesaturated(false)
v.Quantity:Show()
end
return false
end
end
function m:SetMission(mission,party,perc,source)
self.frame.info=mission
self.frame.fromFollowerPage=true
self.frame:EnableMouse(true)
self.frame.party=party
if self.type==Type1 then
addon:DrawSingleButton(source,self.frame,false,false)
self.frame:SetScript("OnEnter",GarrisonMissionButton_OnEnter)
self.frame:SetScript("OnLeave",ns.OnLeave)
else
addon:DrawSlimButton(source,self.frame,false,false)
self.frame:SetScript("OnEnter",nil)
self.frame:SetScript("OnLeave",nil)
end
if self.type==Type2 then
self.frame.Percent:SetFormattedText("%d%%",perc or party.perc)
self.frame.Percent:SetTextColor(addon:GetDifficultyColors(perc or party.perc))
end
end
local function Constructor(type)
unique=unique+1
local frame=CreateFrame("Button",type..unique,nil,"GarrisonMissionListButtonTemplate") --"GarrisonCommanderMissionListButtonTemplate")
frame.Title:SetFontObject("QuestFont_Shadow_Small")
frame.Summary:SetFontObject("QuestFont_Shadow_Small")
frame:SetScript("OnEnter",nil)
frame:SetScript("OnLeave",nil)
frame:RegisterForClicks("LeftButtonUp","RightButtonUp")
frame:SetScript("OnClick",function(self,button) print(button) return button=="RightButton" and self.obj:Fire("OnRightClick",self,button) or self.obj:Fire("OnClick",self,button) end)
frame.LocBG:SetPoint("LEFT")
frame.MissionType:SetPoint("TOPLEFT",5,-2)
--[[
frame.members={}
for i=1,3 do
local f=CreateFrame("Button",nil,frame,"GarrisonCommanderMissionPageFollowerTemplateSmall" )
frame.members[i]=f
f:SetPoint("BOTTOMRIGHT",-65 -65 *i,5)
f:SetScale(0.8)
end
--]]
local widget={}
setmetatable(widget,{__index=frame})
widget.frame=frame
widget.scripts={}
frame.obj=widget
for k,v in pairs(m) do widget[k]=v end
return widget
end
---@function [parent=#GMCMissionButton]
local function Constructor1()
local widget=Constructor(Type1)
widget.type=Type1
return AceGUI:RegisterAsWidget(widget)
end
---@function [parent=#GMCMissionButton]
local function Constructor2()
local widget=Constructor(Type2)
local frame=widget.frame
widget.type=Type2
local indicators=CreateFrame("Frame",nil,frame,"GarrisonCommanderIndicators")
indicators.Percent:SetJustifyH("LEFT")
indicators.Percent:SetJustifyV("CENTER")
indicators:SetPoint("LEFT",70,0)
indicators.Age:Hide()
local spinner=CreateFrame("Frame",nil,frame,"LoadingSpinnerTemplate")
frame.Spinner=spinner
frame.Indicators=indicators
frame.Percent=indicators.Percent
frame.Failure=frame:CreateFontString()
frame.Success=frame:CreateFontString()
frame.Failure:SetFontObject("GameFontRedLarge")
frame.Success:SetFontObject("GameFontGreenLarge")
frame.Failure:SetText(FAILED)
frame.Success:SetText(SUCCESS)
frame.Failure:Hide()
frame.Success:Hide()
frame.Title:SetPoint("TOPLEFT",frame.Indicators,"TOPRIGHT",0,0)
frame.Success:SetPoint("BOTTOMLEFT",frame.Indicators,"BOTTOMRIGHT",0,10)
frame.Failure:SetPoint("BOTTOMLEFT",frame.Indicators,"BOTTOMRIGHT",0,10)
frame.Spinner:SetPoint("BOTTOMLEFT",frame.Indicators,"BOTTOMRIGHT",0,-2)
--widget.frame.MissionType:Hide()
--widget.frame.IconBG:Hide()
return AceGUI:RegisterAsWidget(widget)
end
AceGUI:RegisterWidgetType(Type1,Constructor1,Version)
AceGUI:RegisterWidgetType(Type2,Constructor2,Version)
end
function module:OnInitialized()
GMCGUIContainer()
GMCLayer()
GMCMissionButton()
GMCList()
end