ESO Lua File v100010

libraries/zo_templates/windowtemplates.lua

[◄ back to folders ]
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
--Constants
local DEFAULT_EDIT_BOX_ENABLED_COLOR = ZO_ColorDef:New(1,1,1,1)
local DEFAULT_EDIT_BOX_DISABLED_COLOR = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_DISABLED))
  
function ZO_SelectionHighlight_SetColor(highlight, r, g, b)
    highlight:SetCenterColor(r, g, b, 1)
    highlight:SetEdgeColor(r, g, b, 1)
end
function ZO_SelectionHighlight_Highlight(highlight, control, leftOffset, topOffset, rightOffset, bottomOffset)
    highlight:SetHidden(control == nil)
    
    if(control)
    then
        highlight:ClearAnchors()
        
        if(leftOffset == nil)
        then
            highlight:SetAnchorFill(control)
        else
            highlight:SetAnchor(TOPLEFT, control, TOPLEFT, leftOffset, topOffset)
            highlight:SetAnchor(BOTTOMRIGHT, control, BOTTOMRIGHT, rightOffset, bottomOffset)
        end
    end
end
    GetControl(control, "Top"):SetTextureCoordsRotation(-math.pi / 2)
    GetControl(control, "Left"):SetTextureCoordsRotation(math.pi / 2)
    GetControl(control, "Right"):SetTextureCoordsRotation(-math.pi / 2)
    GetControl(control, "Bottom"):SetTextureCoordsRotation(math.pi / 2)
end
function ZO_DefaultEdit_SetEnabled(editBox, enabled)
    if(enabled) then
        editBox:SetHandler("OnMouseDown", ZO_DefaultEdit_OnMouseDown)
        editBox:SetColor(DEFAULT_EDIT_BOX_ENABLED_COLOR:UnpackRGBA())
    else
        editBox:LoseFocus()
        editBox:SetColor(DEFAULT_EDIT_BOX_DISABLED_COLOR:UnpackRGBA())
        editBox:SetHandler("OnMouseDown", nil)
    end
end
do
    local function SetSelected(self, selected)
        self.selected = selected
        self:RefreshTextColor()
    end
    local function IsSelected(self)
        return self.selected
    end
    local function SetEnabled(self, enabled)
        self.enabled = enabled
        self:RefreshTextColor()
    end
    local function RefreshTextColor(self)
        self:SetColor(self:GetTextColor())
    end
    local function GetTextColor(self)
        if not self.enabled then
            return GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_DISABLED)
        elseif self.selected then
            return GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_SELECTED)
        elseif self.mouseover then
            return GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_HIGHLIGHT)
        else
            return self.normalColor:UnpackRGBA()
        end
    end
    function ZO_SelectableLabel_OnInitialized(label, colorFunction)
        label.selected = false
        label.enabled = true
        label.mouseoverEnabled = true
        label.normalColor = ZO_NORMAL_TEXT
        label.SetSelected = SetSelected
        label.IsSelected = IsSelected
        label.GetTextColor = colorFunction or GetTextColor
        label.RefreshTextColor = RefreshTextColor
        label.SetEnabled = SetEnabled
    end
    function ZO_SelectableLabel_OnMouseEnter(label)
        if(label.mouseoverEnabled) then
            label.mouseover = true
        end
        label:RefreshTextColor()
    end
    function ZO_SelectableLabel_OnMouseExit(label)
        if(label.mouseoverEnabled) then
            label.mouseover = false
        end
        label:RefreshTextColor()
    end
    function ZO_SelectableLabel_SetNormalColor(label, color)
        if color ~= label.normalColor and not label.normalColor:IsEqual(color) then
            label.normalColor = color
            label:RefreshTextColor()
        end
    end
        label.mouseoverEnabled = enabled
    end
end
do
    local function CreateOrGetAnimation(label)
        if not label.showOnMouseOverAnimation then
            label.showOnMouseOverAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("ShowOnMouseOverLabelAnimation", label)
        end
        return label.showOnMouseOverAnimation
    end
    local function SetLockedShown(self, lockedShown)
        self.lockedShown = lockedShown
        local animation = CreateOrGetAnimation(self)
        if lockedShown or self == WINDOW_MANAGER:GetMouseOverControl() then
            animation:PlayForward()
        else
            animation:PlayBackward()
        end
    end
    local function IsLockedShown(self)
        return self.lockedShown
    end
    function ZO_ShowOnMouseOverLabel_OnInitialized(label)
        label.SetLockedShown = SetLockedShown
        label.IsLockedShown = IsLockedShown
        label:SetAlpha(0)
    end
    function ZO_ShowOnMouseOverLabel_OnMouseEnter(label)
        CreateOrGetAnimation(label):PlayForward()
    end
    function ZO_ShowOnMouseOverLabel_OnMouseExit(label)
        if not label.lockedShown then
            CreateOrGetAnimation(label):PlayBackward()
        end
    end
end
do
    local function UpdateVisibility(self)
        local label = GetControl(self, "Text")
        if(self.defaultTextEnabled) then
            if(self:GetText() == "") then
                label:SetHidden(false)
            else
                label:SetHidden(true)
            end
        else
            label:SetHidden(true)
        end
    end
    function ZO_EditDefaultText_Initialize(self, defaultText)
        local label = GetControl(self, "Text")
        label:SetText(defaultText)
        self.defaultTextEnabled = true
        UpdateVisibility(self)
    end
    function ZO_EditDefaultText_Disable(self)
        self.defaultTextEnabled = false
        UpdateVisibility(self)
    end
        UpdateVisibility(self)
    end
end
function ZO_SetupSelectableItemRadialMenuEntryTemplate(template, selected, itemCount)
    if(itemCount) then
        template.count:SetHidden(false)
        template.count:SetText(itemCount)
        if itemCount == 0 then
            template.icon:SetDesaturation(1)
        else
            template.icon:SetDesaturation(0)
        end
    else
        template.count:SetHidden(true)
        template.icon:SetDesaturation(0)
    end
    if selected then
        template.glow:SetAlpha(1)
        template.animation:GetLastAnimation():SetAnimatedControl(nil)
    else
        template.glow:SetAlpha(0)
        template.animation:GetLastAnimation():SetAnimatedControl(template.glow)
    end
end
do
    ZO_RequiredTextFields = ZO_Object:Subclass()
    function ZO_RequiredTextFields:New()
        local obj = ZO_Object.New(self)
        obj.buttons = {}
        obj.editControls = {}
        obj.booleans = {}
        obj.OnTextChanged = function() obj:UpdateButtonEnabled() end
        return obj
    end
    function ZO_RequiredTextFields:AddButton(button)
        table.insert(self.buttons, button)
        self:UpdateButtonEnabled()
    end
    function ZO_RequiredTextFields:SetBoolean(name, value)
        self.booleans[name] = value
        self:UpdateButtonEnabled()
    end
    function ZO_RequiredTextFields:ClearButtons()
        self:SetButtonsEnabled(true)
        self.buttons = {}
    end
     function ZO_RequiredTextFields:SetMatchingString(string)
          self.matchingString = string
          self:UpdateButtonEnabled()
     end
    function ZO_RequiredTextFields:AddTextField(editControl)
        table.insert(self.editControls, editControl)
        ZO_PreHookHandler(editControl, "OnTextChanged", self.OnTextChanged)
        self:UpdateButtonEnabled()
    end
    function ZO_RequiredTextFields:SetButtonsEnabled(enabled)
        local state = enabled and BSTATE_NORMAL or BSTATE_DISABLED
        local locked = not enabled
        for i = 1, #self.buttons do
            self.buttons[i]:SetState(state, locked)
        end
    end
    function ZO_RequiredTextFields:UpdateButtonEnabled()
        if(#self.buttons > 0) then
            for _, value in pairs(self.booleans) do
                if(not value) then
                    self:SetButtonsEnabled(false)
                         return
                end
            end
            for i = 1, #self.editControls do
                   local editText = self.editControls[i]:GetText()
                    if(self.matchingString) then
                         if(self.matchingString ~= editText) then
                              self:SetButtonsEnabled(false)
                              return
                         end
                    else 
                         if(editText == "") then
                              self:SetButtonsEnabled(false)
                              return
                         end
                end
            end
            self:SetButtonsEnabled(true)
        end
    end
end
do
    local function Show(self)
        self:SetHidden(false)
        if(not self.animation) then
            CreateControlFromVirtual("$(parent)Icon", self, "ZO_LoadingIcon")
            self.animation = ANIMATION_MANAGER:CreateTimelineFromVirtual("LoadIconAnimation", GetControl(self, "Icon"))
        end
        
        if(self.text) then
            if(not self.label) then
                self.label = CreateControlFromVirtual("$(parent)Text", self, self.labelTemplate)
            end
            self.label:SetText(self.text)
        end
        self.animation:PlayForward()
    end
    local function Hide(self)
        self:SetHidden(true)
        if(self.animation) then
            self.animation:Stop()
        end
    end
    local function SetText(self, text)
        local textControl = GetControl(self, "Text")
        if(textControl) then
            textControl:SetText(text)
        else
            self.text = text
        end
    end
    function ZO_Loading_Initialize(self, loadText, labelTemplate)
        self.Show = Show
        self.Hide = Hide
        self.SetText = SetText
        self.text = loadText
        self.labelTemplate = labelTemplate or "ZO_LoadingText"
    end
end
do
    function ZO_HelpIcon_OnMouseEnter(self)
        InitializeTooltip(InformationTooltip, self, self.side, 0, 0)
        SetTooltipText(InformationTooltip, self.helpMessage)
    end
    function ZO_HelpIcon_OnMouseExit(self)
        ClearTooltip(InformationTooltip)
    end
    function ZO_HelpIcon_Initialize(self, helpMessage, side)
        self.helpMessage = helpMessage
        self.side = side
    end
end
do
    local g_largeKeyEdgefilePool
    local g_smallKeyEdgefilePool
    local function GetOrCreateKeyEdgefile(largeSize)
        if largeSize then
            if not g_largeKeyEdgefilePool then
                g_largeKeyEdgefilePool = ZO_ControlPool:New("ZO_LargeKeyBackdrop")
                g_largeKeyEdgefilePool:SetCustomResetBehavior(   function(control)
                                                                control:SetParent(nil)
                                                            end)
            end
            return g_largeKeyEdgefilePool:AcquireObject()
        else
            if not g_smallKeyEdgefilePool then
                g_smallKeyEdgefilePool = ZO_ControlPool:New("ZO_SmallKeyBackdrop")
                g_smallKeyEdgefilePool:SetCustomResetBehavior(   function(control)
                                                                control:SetParent(nil)
                                                            end)
            end
            return g_smallKeyEdgefilePool:AcquireObject()
        end
    end
    local function UpdateEdgeFileColor(self, keyEdgeFile)
        if self.edgeFileColor then
            keyEdgeFile:SetCenterColor(self.edgeFileColor:UnpackRGBA())
            keyEdgeFile:SetEdgeColor(self.edgeFileColor:UnpackRGBA())
        else
            keyEdgeFile:SetCenterColor(1, 1, 1, 1)
            keyEdgeFile:SetEdgeColor(1, 1, 1, 1)
        end
    end
    function ZO_KeyMarkupLabel_OnNewUserAreaCreated(self, areaData, areaText, left, right, top, bottom, largeSize)
        if areaData == "key" then
            if not self.keyBackdrops then
                self.keyBackdrops = {}
            end
            local keyEdgeFile, key = GetOrCreateKeyEdgefile(largeSize)
            keyEdgeFile.key = key
            keyEdgeFile:SetParent(self)
            keyEdgeFile:SetAnchor(TOPLEFT, self, TOPLEFT, left, top)
            keyEdgeFile:SetAnchor(BOTTOMRIGHT, self, TOPLEFT, right, bottom)
            UpdateEdgeFileColor(self, keyEdgeFile)
            keyEdgeFile:SetHidden(false)
            self.keyBackdrops[#self.keyBackdrops + 1] = keyEdgeFile
        end
    end
    function ZO_SmallKeyMarkupLabel_OnNewUserAreaCreated(self, areaData, areaText, left, right, top, bottom)
        local leftOffset = left + (self.leftOffset or 2)
        local rightOffset = right + (self.rightOffset or -2)
        local topOffset = top + (self.topOffset or -2)
        local bottomOffset = bottom + (self.bottomOffset or 3)
        ZO_KeyMarkupLabel_OnNewUserAreaCreated(self, areaData, areaText, leftOffset, rightOffset, topOffset, bottomOffset, false)
    end
    function ZO_LargeKeyMarkupLabel_OnNewUserAreaCreated(self, areaData, areaText, left, right, top, bottom)
        local leftOffset = left + (self.leftOffset or 2)
        local rightOffset = right + (self.rightOffset or -2)
        local topOffset = top + (self.topOffset or -1)
        local bottomOffset = bottom + (self.bottomOffset or 1)
        ZO_KeyMarkupLabel_OnNewUserAreaCreated(self, areaData, areaText, leftOffset, rightOffset, topOffset, bottomOffset, true)
    end
        self.edgeFileColor = color
        if self.keyBackdrops then
            for i, keyEdgeFile in ipairs(self.keyBackdrops) do
                UpdateEdgeFileColor(self, keyEdgeFile)
            end
        end
    end
    function ZO_KeyMarkupLabel_SetCustomOffsets(self, left, right, top, bottom)
        self.leftOffset = left
        self.rightOffset = right
        self.topOffset = top
        self.bottomOffset = bottom
    end
    function ZO_KeyMarkupLabel_OnTextChanged(self, largeSize)
        local pool
        if largeSize then
            pool = g_largeKeyEdgefilePool
        else
            pool = g_smallKeyEdgefilePool
        end
        if self.keyBackdrops then
            for i = #self.keyBackdrops, 1, -1 do
                pool:ReleaseObject(self.keyBackdrops[i].key)
                self.keyBackdrops[i] = nil
            end
        end
    end
        ZO_KeyMarkupLabel_OnTextChanged(self, false)
    end
        ZO_KeyMarkupLabel_OnTextChanged(self, true)
    end
end
do
    local g_iconPool
    local VALID_USER_AREAS =
    {
        alliance1 = true,
        alliance2 = true,
        alliance3 = true,
        crowns = true,
    }
    local GUILD_ICON_CONTROLS =
    {
        "alliance1",
        "alliance2",
        "alliance3",
    }
    local function GetTexture(data)
        if data == "alliance1" then
            return GetAllianceBannerIcon(1)
        elseif data == "alliance2" then
            return GetAllianceBannerIcon(2)
        elseif data == "alliance3" then
            return GetAllianceBannerIcon(3)
        elseif data == "crowns" then
            return ZO_CURRENCY_CROWNS_TEXTURE
        end
    end
    local function GetOrCreateIcon()
        if not g_iconPool then
            g_iconPool = ZO_ControlPool:New("ZO_UserAreaIconTexture")
            g_iconPool:SetCustomResetBehavior(   function(control)
                                                            control:SetParent(nil)
                                                        end)
        end
        return g_iconPool:AcquireObject()
    end
    local function OnNewUserAreaCreated(self, areaData, areaText, left, right, top, bottom)
        if VALID_USER_AREAS[areaData] then
            if not self.userAreaIcons then
                self.userAreaIcons = {}
            end
            local icon, key = GetOrCreateIcon()
            icon.key = key
            icon:SetParent(self)
            icon:SetAnchor(TOPLEFT, self, TOPLEFT, left, top)
            icon:SetAnchor(BOTTOMRIGHT, self, TOPLEFT, right, bottom)
            icon:SetHidden(false)
            self.userAreaIcons[#self.userAreaIcons + 1] = icon
            icon:SetTexture(GetTexture(areaData))
        end
    end
    local NEGATIVE_LEFT_OFFSET = -5
    local ICON_WIDTH = 32
    local ICON_HEIGHT = 32
    function ZO_UserAreaIconMarkupLabel_OnNewUserAreaCreated(self, areaData, areaText, left, _, top, bottom)
        local leftOffset = left + NEGATIVE_LEFT_OFFSET
        local rightOffset = leftOffset + ICON_WIDTH
        local verticalOffset = ((bottom - top - ICON_HEIGHT) / 2)
        local topOffset = top + verticalOffset
        local bottomOffset = topOffset + ICON_HEIGHT
        OnNewUserAreaCreated(self, areaData, areaText, leftOffset, rightOffset, topOffset, bottomOffset)
    end
        if self.userAreaIcons then
            for i = #self.userAreaIcons, 1, -1 do
                g_iconPool:ReleaseObject(self.userAreaIcons[i].key)
                self.userAreaIcons[i] = nil
            end
        end
    end
    function ZO_PrefixIconNameFormatter(iconAreaData, name)
        return string.format("|u28:0:%s:%s|u", iconAreaData, name)
    end
    function ZO_GetAllianceIconUserAreaDataName(allianceId)
        return GUILD_ICON_CONTROLS[allianceId]
    end
end
do
    local function Start(self, remainingTimeMs)
        self:StartCooldown(remainingTimeMs, remainingTimeMs, CD_TYPE_RADIAL, CD_TIME_TYPE_TIME_UNTIL, NO_LEADING_EDGE)
        local nowS = GetFrameTimeSeconds()
        self.endTimeS = nowS + (remainingTimeMs / 1000)
        self.lastUpdateS = nowS
        if(self.numWarningSounds > 0) then
            EVENT_MANAGER:RegisterForUpdate(self:GetName(), 20, function(timeMS)
                local timeS = timeMS / 1000
                if(timeS < self.endTimeS and timeS >= self.endTimeS - self.numWarningSounds) then
                    local lastUpdateSecPart = zo_floor(self.lastUpdateS)
                    local nowSecPart = zo_floor(timeS)
                    if(lastUpdateSecPart ~= nowSecPart) then
                        PlaySound(SOUNDS.COUNTDOWN_WARNING)
                        if(not self.pulseTimeline) then
                            self.pulseTimeline = ANIMATION_MANAGER:CreateTimelineFromVirtual("ZO_RadialCountdownTimerPulse", self)
                        end
                        self.pulseTimeline:PlayFromStart()
                    end
                end
                self.lastUpdateS = timeS
            end)
        end
    end
    local function Stop(self)
        self:ResetCooldown()
        self.lastUpdateS = nil
        self.endTimeS = nil
        EVENT_MANAGER:UnregisterForUpdate(self:GetName())
    end
    local function SetNumWarningSounds(self, numWarningSounds)
        self.numWarningSounds = numWarningSounds
    end
        self.numWarningSounds = 0
        self.Start = Start
        self.Stop = Stop
    end
end
ZO_SimpleControlScaleInterpolator = ZO_Object:Subclass()
function ZO_SimpleControlScaleInterpolator:New(...)
    local interpolator = ZO_Object.New(self)
    interpolator:Initialize(...)
    return interpolator
end
function ZO_SimpleControlScaleInterpolator:Initialize(minScale, maxScale)
    self.minScale = minScale
    self.maxScale = maxScale
    self.controlsToTarget = {}
    EVENT_MANAGER:RegisterForUpdate(tostring(self), 0, function() self:OnUpdate() end)
end
function ZO_SimpleControlScaleInterpolator:ScaleUp(control)
    self.controlsToTarget[control] = self.maxScale
end
function ZO_SimpleControlScaleInterpolator:ScaleDown(control)
    self.controlsToTarget[control] = self.minScale
end
function ZO_SimpleControlScaleInterpolator:ResetToMax(control)
    self.controlsToTarget[control] = nil
    control:SetScale(self.maxScale)
end
function ZO_SimpleControlScaleInterpolator:ResetToMin(control)
    self.controlsToTarget[control] = nil
    control:SetScale(self.minScale)
end
function ZO_SimpleControlScaleInterpolator:ResetAll()
    for control, target in pairs(self.controlsToTarget) do
        self:ResetToMin(control)
    end
end
function ZO_SimpleControlScaleInterpolator:OnUpdate()
    for control, target in pairs(self.controlsToTarget) do
        local delta = target - control:GetScale()
        if zo_abs(delta) < .0025 then
            control:SetScale(target)
            self.controlsToTarget[control] = nil
        else
            control:SetScale(zo_deltaNormalizedLerp(control:GetScale(), target, .2))
        end
    end
end
    self.glow = self:GetNamedChild("Glow")
    self.icon = self:GetNamedChild("Icon")
    self.count = self:GetNamedChild("CountText")
end