ESO Lua File v100010

ingame/crafting/craftingresults.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
ZO_CraftingResults = ZO_Object:Subclass()
local MAX_TRAIT_CONTROLS = 5
function ZO_CraftingResults:New(...)
    local craftingResults = ZO_Object.New(self)
    craftingResults:Initialize(...)
    return craftingResults
end
function ZO_CraftingResults:Initialize(control)
    self.control = control
    control:RegisterForEvent(EVENT_CRAFT_STARTED, function(eventCode, ...) self:OnCraftStarted(...) end)
    control:RegisterForEvent(EVENT_CRAFT_COMPLETED, function(eventCode, ...) self:OnCraftCompleted(...) end)
    self.enchantSoundPlayer = ZO_QueuedSoundPlayer:New()
    self.enchantSoundPlayer:SetFinishedAllSoundsCallback(function() self:OnAllEnchantSoundsFinished() end)
end
function ZO_CraftingResults:SetCraftingTooltip(tooltipControl)
    if self.tooltipControl ~= tooltipControl then
        self.tooltipAnimationSuccessSound = nil
        self.tooltipAnimationFailureSound = nil
        self.tooltipControl = tooltipControl
        self:ForceStop()
        if self.tooltipControl then
            self:AssociateAnimations(self.tooltipControl)
        end
    end
    self.notifier:FadeAll()
end
function ZO_CraftingResults:SetTooltipAnimationSounds(tooltipAnimationSuccessSound, tooltipAnimationFailureSound)
    self.tooltipAnimationSuccessSound = tooltipAnimationSuccessSound
    self.tooltipAnimationFailureSound = tooltipAnimationFailureSound
end
function ZO_CraftingResults:InitializeResultBuffer()
    self.notifier = ZO_FadingControlBuffer:New(self.control, 5, "CraftingResultFade", "CraftingResultTranslate")
    self.notifier:SetTranslateDuration(500)
    self.notifier:SetHoldTimes(5000)
    self.notifier:SetAdditionalVerticalSpacing(5)
    self.notifier:SetFadesInImmediately(true)
    local function PlayPulse(control)
        if not control.pulseAnimation then
            local pulseTexture = CreateControlFromVirtual("$(parent)PulseTexture", control, "ZO_CraftingResultPulseTexture")
            control.pulseAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("CraftingResultPulse", pulseTexture)
        end
        if not control.pulseAnimation:IsPlaying() then
            control.pulseAnimation:PlayFromStart()
        end
    end
    local function SetupItem(control, name, icon, stack, sellPrice, meetsUsageRequirement, equipType, itemStyle, quality, itemSoundCategory, itemInstanceId)
        local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, quality)
        control:SetText(zo_strformat(SI_TOOLTIP_ITEM_NAME, name))
        control:SetColor(r, g, b, 1)
        local inventorySlot = GetControl(control, "Button")
        ZO_Inventory_SetupSlot(inventorySlot, stack, icon, meetsUsageRequirement)
    end
    local STACK_INDEX = 3
    local ITEM_INSTANCE_INDEX = 10
    local function AreItemsEqual(otherData, ...)
        return otherData[ITEM_INSTANCE_INDEX] == select(ITEM_INSTANCE_INDEX, ...)
    end
    local function ItemEqualitySetup(control, dataTable, name, icon, stack, sellPrice, meetsUsageRequirement, equipType, itemStyle, quality, itemSoundCategory, itemInstanceId)
        dataTable[STACK_INDEX] = dataTable[STACK_INDEX] + stack
        local inventorySlot = GetControl(control, "Button")
        ZO_Inventory_SetupSlot(inventorySlot, dataTable[STACK_INDEX], icon, meetsUsageRequirement)
        PlayPulse(inventorySlot)
    end
    self.notifier:AddTemplate("ZO_CraftingResultItem", SetupItem, AreItemsEqual, ItemEqualitySetup)
end
local MAX_RUNE_ROWS = 3
local function RegisterEnchantDialog(dialogName, control)
    local function SetupEnchantDialog(dialog)
        local numTranslation = GetNumLastCraftingResultLearnedTranslations()
        for i = 1, numTranslation do
            local translationName, itemName, icon, _, _, _, _, quality = GetLastCraftingResultLearnedTranslationInfo(i)
            local row = control:GetNamedChild("Row" .. i)
            row:SetHidden(false)
            row.icon:SetTexture(icon)
            row.itemName:SetText(zo_strformat(SI_TOOLTIP_ITEM_NAME, itemName))
            local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, quality)
            row.itemName:SetColor(r, g, b, 1)
            row.translatedName:SetText(translationName)
        end
        for i = numTranslation + 1, MAX_RUNE_ROWS do
            control:GetNamedChild("Row" .. i):SetHidden(true)
        end
    end
    ZO_Dialogs_RegisterCustomDialog(dialogName,
    {
        customControl = control,
        setup = SetupEnchantDialog,
        title =
        {
            text = SI_ENCHANTING_TRANSLATION_LEARNED_DIALOG_TITLE,
        },
        buttons =
        {
            {
                keybind = "DIALOG_NEGATIVE",
                control = control:GetNamedChild("Exit"),
                text = SI_EXIT_BUTTON,
            },
        }
    }) 
end
local function RegisterEnchantDialog(dialogName, control)
    local function SetupEnchantDialog(dialog)
        local numTranslation = GetNumLastCraftingResultLearnedTranslations()
        for i = 1, numTranslation do
            local translationName, itemName, icon, _, _, _, _, quality = GetLastCraftingResultLearnedTranslationInfo(i)
            local row = control:GetNamedChild("Row" .. i)
            row:SetHidden(false)
            row.icon:SetTexture(icon)
            row.itemName:SetText(zo_strformat(SI_TOOLTIP_ITEM_NAME, itemName))
            local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, quality)
            row.itemName:SetColor(r, g, b, 1)
            row.translatedName:SetText(translationName)
        end
        for i = numTranslation + 1, MAX_RUNE_ROWS do
            control:GetNamedChild("Row" .. i):SetHidden(true)
        end
    end
    ZO_Dialogs_RegisterCustomDialog(dialogName,
    {
        customControl = control,
        setup = SetupEnchantDialog,
        title =
        {
            text = SI_ENCHANTING_TRANSLATION_LEARNED_DIALOG_TITLE,
        },
        buttons =
        {
            {
                keybind = "DIALOG_NEGATIVE",
                control = control:GetNamedChild("Exit"),
                text = SI_EXIT_BUTTON,
            },
        }
    }) 
end
local function RegisterGamepadEnchantDialog(dialogName, control)
    local function SetupEnchantDialog(dialog)
        local numTranslation = GetNumLastCraftingResultLearnedTranslations()
        for i = 1, numTranslation do
            local translationName, itemName, icon, _, _, _, _, quality = GetLastCraftingResultLearnedTranslationInfo(i)
            local row = control:GetNamedChild("Row" .. i)
            row:SetHidden(false)
            row.icon:SetTexture(icon)
            row.itemName:SetText(zo_strformat(SI_GAMEPAD_ENCHANTING_TRANSLATION_KNOWN, itemName, translationName))
            local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, quality)
            row.itemName:SetColor(r, g, b, 1)
        end
        for i = numTranslation + 1, MAX_RUNE_ROWS do
            control:GetNamedChild("Row" .. i):SetHidden(true)
        end
    end
    ZO_Dialogs_RegisterCustomDialog(dialogName,
    {
        customControl = control,
        setup = SetupEnchantDialog,
        title =
        {
            text = SI_ENCHANTING_TRANSLATION_LEARNED_DIALOG_TITLE,
        },
        buttons =
        {
            {
                keybind = "DIALOG_NEGATIVE",
                control = control:GetNamedChild("Exit"),
                text = SI_EXIT_BUTTON,
            },
        }
    }) 
end
function ZO_CraftingResults:InitializeEnchantDialog()
    RegisterGamepadEnchantDialog("GAMEPAD_ENCHANT_TRANSLATION_LEARNED", ZO_CraftingResultEnchantDialog_Gamepad)
    RegisterEnchantDialog("ENCHANT_TRANSLATION_LEARNED", ZO_CraftingResultEnchantDialog)
end
local MAX_ALCHEMY_ROWS = 3
local MAX_ITEM_TRAITS = 4
local function SetDefaultOptionValue(options, optionName, defaultValue)
    if options[optionName] == nil then
        options[optionName] = defaultValue
    end
end
-- The options parameter is a table that can contain any of the following values:
-- colorItemName: Whether to apply the quality color for the reagent name label (defaults to true)
-- centerAlignTraits: Whether to center-align traits relative to reagent label (defaults to true)
-- rowSpacing: The amount of spacing between reagent rows (defaults to 40)
    -- Set default values for options
    if not options then
        options = {}
    end
    SetDefaultOptionValue(options, "colorItemName", true)
    SetDefaultOptionValue(options, "centerAlignTraits", true)
    SetDefaultOptionValue(options, "rowSpacing", 40)
    local numLearnedTraits = GetNumLastCraftingResultLearnedTraits()
    local itemNameToRow = {}
    local currentRowIndex = 1
    for i = 1, numLearnedTraits do
        local traitName, itemName, icon, sellPrice, meetsUsageRequirement, equipType, itemStyle, quality = GetLastCraftingResultLearnedTraitInfo(i)
        
        if not itemNameToRow[itemName] then
            local row = control:GetNamedChild("Row" .. currentRowIndex)
            currentRowIndex = currentRowIndex + 1
            itemNameToRow[itemName] = row
            row:SetHidden(false)
            row.icon:SetTexture(icon)
            row.itemName:SetText(zo_strformat(SI_TOOLTIP_ITEM_NAME, itemName))
                
            if options.colorItemName then
                local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, quality)
                row.itemName:SetColor(r, g, b, 1)
            end
            row.containerHeight = 0
               
            for traitIndex = 2, MAX_ITEM_TRAITS do
                row.traits[traitIndex]:SetHidden(true)
            end
            row.currentTraitIndex = 1
        end
        local row = itemNameToRow[itemName]
        local currentTraitIndex = row.currentTraitIndex
        row.traits[currentTraitIndex]:SetText(zo_strformat(SI_ALCHEMY_REAGENT_TRAIT_FORMATTER, traitName))
        row.traits[currentTraitIndex]:SetHidden(false)
        row.currentTraitIndex = currentTraitIndex + 1
        row.containerHeight = row.containerHeight + select(2, row.traits[currentTraitIndex]:GetTextDimensions())
    end
        
    for i = currentRowIndex, MAX_ALCHEMY_ROWS do
        control:GetNamedChild("Row" .. i):SetHidden(true)
    end
    for i = 1, currentRowIndex - 1 do
        local row = control:GetNamedChild("Row" .. i)
        row.traitContainer:SetHeight(row.containerHeight)
        local currentOffset = zo_max(row.containerHeight - row:GetHeight(), 0) * .5 + 10
        if i == 1 then
            if options.centerAlignTraits then
                row:SetAnchor(TOP, control:GetNamedChild("Description"), BOTTOM, 0, currentOffset)
            else
                currentOffset = 60
                row:SetAnchor(TOPLEFT, control:GetNamedChild("Description"), BOTTOMLEFT, 0, currentOffset)
            end
        else
            local prevRow = control:GetNamedChild("Row" .. (i - 1))
            local totalOffset
            if options.centerAlignTraits then
                local prevOffset = zo_max(prevRow.containerHeight - prevRow:GetHeight(), 0) * .5 + 10
                totalOffset = prevOffset + currentOffset
            else
                totalOffset = prevRow.containerHeight + options.rowSpacing
            end
            row:SetAnchor(TOP, prevRow, BOTTOM, 0, totalOffset)
        end
    end
    if not options.centerAlignTraits then
        local prevRow = control:GetNamedChild("Row" .. currentRowIndex - 1);
        control:GetNamedChild("Exit"):SetAnchor(TOPLEFT, prevRow, BOTTOMLEFT, 0, prevRow.containerHeight + options.rowSpacing)
    end
end
local function RegisterAlchemyDialog(dialogName, control, options)
    local function SetupAlchemyDialog(dialog)
    end
    ZO_Dialogs_RegisterCustomDialog(dialogName,
    {
        customControl = control,
        setup = SetupAlchemyDialog,
        title =
        {
            text = SI_ALCHEMY_REAGENT_TRAIT_LEARNED_DIALOG_TITLE,
        },
        buttons =
        {
            {
                keybind = "DIALOG_NEGATIVE",
                control = control:GetNamedChild("Exit"),
                text = SI_EXIT_BUTTON,
            },
        }
    })
end
function ZO_CraftingResults:InitializeAlchemyDialog()
    local options = {
        colorItemName = true,
        centerAlignTraits = true,
        rowSpacing = 40,
    }
    RegisterAlchemyDialog("ALCHEMY_TRAITS_LEARNED", ZO_CraftingResultAlchemyDialog, options)
    options = {
        colorItemName = false,
        centerAlignTraits = false,
        rowSpacing = 30,
    }
    RegisterAlchemyDialog("GAMEPAD_ALCHEMY_TRAITS_LEARNED", ZO_GamepadCraftingResultAlchemyDialog, options)
end
function ZO_CraftingResults:PlayCraftedSound(itemSoundCategory)
    if not ZO_Enchanting_IsInCreationMode() then
        PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_CRAFTED)
    end
end
function ZO_CraftingResults:AssociateAnimations(tooltip)
    if not self.resultTooltipAnimation then
        self.resultTooltipAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("CraftingResultTooltipAnimation")
    end
    self.resultTooltipAnimation:GetAnimation(1):SetAnimatedControl(tooltip)
    self.resultTooltipAnimation:GetAnimation(2):SetAnimatedControl(tooltip)
    local tooltipGlow = tooltip:GetNamedChild("Glow")
    self.tooltipGlow = tooltipGlow
    self.resultTooltipAnimation:GetAnimation(3):SetAnimatedControl(tooltipGlow)
    local tooltipBurst1 = tooltip:GetNamedChild("Burst1")
    self.tooltipBurst1 = tooltipBurst1
    self.resultTooltipAnimation:GetAnimation(4):SetAnimatedControl(tooltipBurst1)
    local tooltipBurst2 = tooltip:GetNamedChild("Burst2")
    self.tooltipBurst2 = tooltipBurst2
    self.resultTooltipAnimation:GetAnimation(5):SetAnimatedControl(tooltipBurst2)
    self.resultTooltipAnimation:GetAnimationTimeline(1):GetAnimation(1):SetAnimatedControl(tooltipBurst1)
    self.resultTooltipAnimation:GetAnimationTimeline(1):GetAnimation(2):SetAnimatedControl(tooltipBurst2)
    local function OnStop(animation)
        tooltipGlow:SetAlpha(0)
        tooltipBurst1:SetAlpha(0)
        tooltipBurst2:SetAlpha(0)
        self:OnTooltipAnimationStopped()
    end
    self.forceStopHandler = function()
        tooltip:SetAlpha(1)
        OnStop()
    end
    self.resultTooltipAnimation:GetAnimation(1):SetHandler("OnStop", OnStop)
end
function ZO_CraftingResults:ForceStop()
    if self.resultTooltipAnimation and self.resultTooltipAnimation:IsPlaying() then
        self.resultTooltipAnimation:Stop()
        self.forceStopHandler()
    end
end
local function DoesCraftingTypeHaveSlotAnimations(craftingType)
    if craftingType == CRAFTING_TYPE_PROVISIONING then
        return false
    elseif craftingType == CRAFTING_TYPE_ENCHANTING then
        return true
    elseif craftingType == CRAFTING_TYPE_ALCHEMY then
        return true
    elseif ZO_Smithing_IsSmithingStation(craftingType) then
        local activeSmithing = ZO_Smithing_GetActiveObject()
        return activeSmithing and activeSmithing:DoesCurrentModeHaveSlotAnimations() or true
    end
end
function ZO_CraftingResults:OnCraftStarted(craftingType)
    self.tooltipAnimationCompleted = false
    self.craftingProcessCompleted = false
    if (ZO_Enchanting_IsInCreationMode()) then
        local potencySound, potencyLength, essenceSound, essenceLength, aspectSound, aspectLength = ZO_Enchanting_GetVisibleEnchanting():GetLastRunestoneSoundParams()
        self.enchantSoundPlayer:PlaySound(potencySound, potencyLength)
        self.enchantSoundPlayer:PlaySound(essenceSound, essenceLength)
        self.enchantSoundPlayer:PlaySound(aspectSound, aspectLength)
    end
    CALLBACK_MANAGER:FireCallbacks("CraftingAnimationsStarted")
    if not DoesCraftingTypeHaveSlotAnimations(craftingType) then
        self:PlayTooltipAnimation()
    end
end
function ZO_CraftingResults:PlayTooltipAnimation(failure)
    if self.tooltipControl and not self.tooltipControl:IsHidden() then
        self:ForceStop()
        self.tooltipGlow:SetEdgeTexture(failure and "EsoUI/Art/Crafting/crafting_toolTip_glow_edge_red64.dds" or "EsoUI/Art/Crafting/crafting_toolTip_glow_edge_blue64.dds", 512, 64)
        if failure then
            self.resultTooltipAnimation:GetAnimation(3):SetDuration(200)
            self.resultTooltipAnimation:GetAnimation(3):SetAlphaValues(.25, 1)
        else
            self.resultTooltipAnimation:GetAnimation(3):SetDuration(500)
            self.resultTooltipAnimation:GetAnimation(3):SetAlphaValues(0, 1)
        end
        self.tooltipBurst1:SetHidden(failure)
        self.tooltipBurst2:SetHidden(failure)
        self.resultTooltipAnimation:PlayFromStart()
        PlaySound(failure and self.tooltipAnimationFailureSound or self.tooltipAnimationSuccessSound)
    else
        self:OnTooltipAnimationStopped()
    end
end
function ZO_CraftingResults:OnCraftCompleted(craftingType)
    if not self.enchantSoundPlayer:IsPlaying() and not self.craftingProcessCompleted then
        self.craftingProcessCompleted = true
        if DoesCraftingTypeHaveSlotAnimations(craftingType) then
               local numItemsGained = GetNumLastCraftingResultItemsAndPenalty()
            self:PlayTooltipAnimation(numItemsGained == 0)
        else
            self:CheckCraftProcessCompleted()
        end
    end
end
function ZO_CraftingResults:OnAllEnchantSoundsFinished()
    if not self.craftingProcessCompleted then
        self.craftingProcessCompleted = true
        self:PlayTooltipAnimation()
    end
end
function ZO_CraftingResults:OnTooltipAnimationStopped()
    if self.tooltipAnimationCompleted == false then
        self.tooltipAnimationCompleted = true
        self:CheckCraftProcessCompleted()
    end
end
    local craftingType = GetCraftingInteractionType()
    if craftingType == CRAFTING_TYPE_BLACKSMITHING then
        return ITEMTYPE_BLACKSMITHING_BOOSTER
    elseif craftingType == CRAFTING_TYPE_CLOTHIER then
        return ITEMTYPE_CLOTHIER_BOOSTER
    elseif craftingType == CRAFTING_TYPE_WOODWORKING then
        return ITEMTYPE_WOODWORKING_BOOSTER
    end
end
    local craftingType = GetCraftingInteractionType()
    if craftingType == CRAFTING_TYPE_BLACKSMITHING then
        return SOUNDS.BLACKSMITH_EXTRACTED_BOOSTER
    elseif craftingType == CRAFTING_TYPE_CLOTHIER then
        return SOUNDS.CLOTHIER_EXTRACTED_BOOSTER
    elseif craftingType == CRAFTING_TYPE_WOODWORKING then
        return SOUNDS.WOODWORKER_EXTRACTED_BOOSTER
    end
end
    local craftingType = GetCraftingInteractionType()
    if craftingType == CRAFTING_TYPE_BLACKSMITHING then
        return SI_SMITHING_BLACKSMITH_EXTRACTION_FAILED, SOUNDS.BLACKSMITH_FAILED_EXTRACTION
    elseif craftingType == CRAFTING_TYPE_CLOTHIER then
        return SI_SMITHING_CLOTHIER_EXTRACTION_FAILED, SOUNDS.CLOTHIER_FAILED_EXTRACTION
    elseif craftingType == CRAFTING_TYPE_WOODWORKING then
        return SI_SMITHING_WOODWORKING_EXTRACTION_FAILED, SOUNDS.WOODWORKER_FAILED_EXTRACTION
    end
end
local function DidLastCraftGainBooster(numItemsGained)
    local smithingObject = ZO_Smithing_GetActiveObject()
    if smithingObject and smithingObject:IsExtracting() then
        local boosterItemType = GetBoosterItemTypeForCraftingType()
        for i = 1, numItemsGained do
            local name, icon, stack, sellPrice, meetsUsageRequirement, equipType, itemType, itemStyle, quality, itemSoundCategory, itemInstanceId = GetLastCraftingResultItemInfo(i)
            if itemType == boosterItemType then
                return true
            end
        end
    end
    return false
end
function ZO_CraftingResults:CheckCraftProcessCompleted()
    if self.craftingProcessCompleted and self.tooltipAnimationCompleted then
        local numItemsGained, penaltyApplied = GetNumLastCraftingResultItemsAndPenalty()
         local smithingObject = ZO_Smithing_GetActiveObject()
        local isImproving = smithingObject and smithingObject:IsImproving()
 
        if GetNumLastCraftingResultLearnedTraits() > 0 then
            local dialogName = IsInGamepadPreferredMode() and "GAMEPAD_ALCHEMY_TRAITS_LEARNED" or "ALCHEMY_TRAITS_LEARNED"
            ZO_Dialogs_ShowDialog(dialogName)
        end
          if penaltyApplied then
               TriggerTutorial(TUTORIAL_TRIGGER_DECONSTRUCTION_LEVEL_PENALTY)
          end
        if numItemsGained == 0 then
            if SYSTEMS:IsShowing("alchemy") then
                ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_ALCHEMY_NO_YIELD)
            elseif isImproving then
                ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_SMITHING_IMPROVEMENT_FAILED)
            elseif smithingObject and smithingObject:IsExtracting() then
                    local failedExtractionStringId, failedExtractionSoundName = GetFailedSmithingExtractionResultInfo()
                    if penaltyApplied then
                         ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, failedExtractionSoundName, SI_SMITHING_DECONSTRUCTION_LEVEL_PENALTY)
                    else
                         ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, failedExtractionSoundName, failedExtractionStringId)
                    end
            end
        else
            local gainedBooster = DidLastCraftGainBooster(numItemsGained)
            local shouldDisplayMessages = not isImproving and CENTER_SCREEN_ANNOUNCE:IsInactive() -- there is special messaging for improvement
            for i = 1, numItemsGained do
                local name, icon, stack, sellPrice, meetsUsageRequirement, equipType, itemType, itemStyle, quality, itemSoundCategory, itemInstanceId = GetLastCraftingResultItemInfo(i)
                -- Don't save messages if we can't display them immediately
                if shouldDisplayMessages then
                     -- Gamepad crafting will use alert text
                    if IsInGamepadPreferredMode() then
                        ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, zo_strformat(SI_GAMEPAD_CRAFTING_COMPLETED_ITEM, name))
                    else
                            self.notifier:AddMessage("ZO_CraftingResultItem", name, icon, stack, sellPrice, meetsUsageRequirement, equipType, itemStyle, quality, itemSoundCategory, itemInstanceId)
                        end
                end
                if not gainedBooster then
                    self:PlayCraftedSound(itemSoundCategory)
                end
            end
            if gainedBooster then
                PlaySound(GetBoosterFoundSoundForCraftingType())
            end
            if isImproving then
                ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_SMITHING_IMPROVEMENT_SUCCESS)
               elseif penaltyApplied then
                    ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_SMITHING_DECONSTRUCTION_LEVEL_PENALTY)
               end
        end
        local totalInspiration = GetLastCraftingResultTotalInspiration()
        if totalInspiration > 0 then
            PlaySound(SOUNDS.CRAFTING_GAINED_INSPIRATION)
        end
        CALLBACK_MANAGER:FireCallbacks("CraftingAnimationsStopped")
        if GetNumLastCraftingResultLearnedTranslations() > 0 then
            local dialogName = IsInGamepadPreferredMode() and "GAMEPAD_ENCHANT_TRANSLATION_LEARNED" or "ENCHANT_TRANSLATION_LEARNED"
            ZO_Dialogs_ShowDialog(dialogName)
        end
    end
end
function ZO_CraftingResults:ClearAll()
    self.notifier:ClearAll()
end
    CRAFTING_RESULTS = ZO_CraftingResults:New(control)
    CRAFTING_RESULTS_FRAGMENT = ZO_FadeSceneFragment:New(control)
    CRAFTING_RESULTS_FRAGMENT:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_HIDDEN then
            CRAFTING_RESULTS:ClearAll()
        end
    end)
end