ESO Lua File v100010

pregame/gamecredits/gamecredits.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
local g_pools = {}
local g_translateAnimationPool
local g_currentEntryIndex
local g_numCreditsEntries
local g_scrollParent
--local g_crossfade
local function AddPool(poolType, template, setupCallback)
    g_pools[poolType] =
    {
        pool = ZO_ControlPool:New(template, g_scrollParent),
        setupCallback = setupCallback,
    }
end
local function AcquireControl(entryType, entryData, additionalData)
    local poolData = g_pools[entryType]
    local control, key = poolData.pool:AcquireObject()
    control.key = key
    control.entryType = entryType
    
    control:SetAnchor(TOP, g_scrollParent, BOTTOM)
    local controlHeight, onExitCallback = poolData.setupCallback(control, entryData, additionalData)
    return controlHeight, control, onExitCallback
end
local function ReleaseEntry(control)
    local key = control.key
    local entryType = control.entryType
    control.key = nil
    control.entryType = nil
    g_pools[entryType].pool:ReleaseObject(key)
end
local function SetupTextControl(control, text)
    control:SetText(text)
    return select(2, control:GetTextDimensions())
end
local function SetupLogoControl(control, textureFile, height)
    control:SetTexture(textureFile)
    return tonumber(height)
end
local function OnBGExitCallback(timeline, offset)
    --g_crossfade:DoCrossfade(timeline.control.textureFile)
end
local function SetupBackgroundSwitch(control, textureFile)
    control.textureFile = textureFile
    control:SetTexture(textureFile) -- won't display anything, just loads this image so it's ready to go
    return 0, OnBGExitCallback -- control is invisible, doesn't need a height. OnExitCallback used here to do transition when the control exits the window
end
local function SetupPaddingSection(control, unused, height)
    return tonumber(height)
end
local CREDITS_SCROLL_SPEED = 75 -- pixels per second
local function AddNextEntry()
    if(g_currentEntryIndex <= g_numCreditsEntries) then
        local entryType, entryData, additionalData = GetGameCreditsEntry(g_currentEntryIndex)
        local controlHeight, control, onExitCallback = AcquireControl(entryType, entryData, additionalData)
        local translateTimeline, translateKey = g_translateAnimationPool:AcquireObject()
        local translateAnim = translateTimeline:GetAnimation(1)
        translateTimeline.key = translateKey
        translateTimeline.control = control
        translateTimeline:ApplyAllAnimationsToControl(control)
        local scrollHeight = ZO_GameCreditsScroll:GetHeight()
        local scrollDistance = scrollHeight + controlHeight
        local scrollTimeMS = (scrollDistance / CREDITS_SCROLL_SPEED) * 1000
        local addNextEntryTime = zo_max(16, (controlHeight / CREDITS_SCROLL_SPEED) * 1000) -- The zo_max is to add at least some amount of time before the next entry is added.
        local onExitTime = (scrollHeight / CREDITS_SCROLL_SPEED) * 1000
        
        translateAnim:SetTranslateDeltas(0, -scrollDistance)
        translateAnim:SetDuration(scrollTimeMS)
        translateTimeline:ClearAllCallbacks()
        translateTimeline:InsertCallback(AddNextEntryAnimationTrigger, addNextEntryTime)
        if(onExitCallback) then
            translateTimeline:InsertCallback(onExitCallback, onExitTime)
        end
        translateTimeline:PlayFromStart()
        g_currentEntryIndex = g_currentEntryIndex + 1
    end
end
AddNextEntryAnimationTrigger = function(timeline, offset)
    if(g_currentEntryIndex > g_numCreditsEntries) then
        timeline.stopCreditsRollWhenFinished = true
    else
        AddNextEntry()
    end
end
local function TimelineRelease(timeline)
    ReleaseEntry(timeline.control)
    timeline.key = nil
    timeline.control = nil
    timeline.stopCreditsRollWhenFinished = nil
end
local function ReleaseSection(timeline, completedPlaying)
    if(completedPlaying) then
        local stopCredits = timeline.stopCreditsRollWhenFinished
        g_translateAnimationPool:ReleaseObject(timeline.key)
        if(stopCredits) then
            ZO_GameCredits_Exit()
        end
    end
end
local function BeginCredits()
    g_numCreditsEntries = GetNumGameCreditsEntries()
    g_currentEntryIndex = 1
    g_currentDrawLevel = 1
    if(g_numCreditsEntries > 0) then
        AddNextEntry()
    end
end
    g_scrollParent = self:GetNamedChild("Scroll")
    -- Additional code was removed that would initialize the loading screen backgrounds that
    -- would need to be added to resume use of bg crossfades.
    --g_crossfade = ZO_CrossfadeBG_GetObject(self:GetNamedChild("BG"))
    -- NOTE: Templates must be unique due to how the object pools name controls as they're created.
    AddPool(GAME_CREDITS_ENTRY_TYPE_DEPARTMENT_HEADER, "ZO_GameCreditsDepartment", SetupTextControl)
    AddPool(GAME_CREDITS_ENTRY_TYPE_SECTION_HEADER, "ZO_GameCreditsSection", SetupTextControl)
    AddPool(GAME_CREDITS_ENTRY_TYPE_SECTION_TEXT, "ZO_GameCreditsNames", SetupTextControl)
    AddPool(GAME_CREDITS_ENTRY_TYPE_SECTION_TEXT_BLOCK, "ZO_GameCreditsTextBlock", SetupTextControl)
    AddPool(GAME_CREDITS_ENTRY_TYPE_COMPANY_LOGO, "ZO_GameCreditsLogo", SetupLogoControl)
    AddPool(GAME_CREDITS_ENTRY_TYPE_BACKGROUND_SWITCH, "ZO_GameCreditsBGSwitch", SetupBackgroundSwitch)
    AddPool(GAME_CREDITS_ENTRY_TYPE_PADDING_SECTION, "ZO_GameCreditsPadding", SetupPaddingSection)
    
    g_translateAnimationPool = ZO_AnimationPool:New("GameCreditsTranslate")
    g_translateAnimationPool:SetCustomResetBehavior(TimelineRelease)
    
    EVENT_MANAGER:RegisterForEvent("GameCredits", EVENT_GAME_CREDITS_READY, BeginCredits)
    GAME_CREDITS_FRAGMENT = ZO_FadeSceneFragment:New(self)
    GAME_CREDITS_FRAGMENT:RegisterCallback("StateChange",   function(oldState, newState)
                                                                if(newState == SCENE_FRAGMENT_SHOWING) then
                                                                    ShowCredits()
                                                                elseif(newState == SCENE_FRAGMENT_HIDDEN) then
                                                                    StopCredits()
                                                                    g_translateAnimationPool:ReleaseAllObjects()
                                                                end
                                                            end)
end
function ZO_GameCredits_ReleaseSection(timeline, completedPlaying)
    ReleaseSection(timeline, completedPlaying)
end
function ZO_GameCredits_Exit()
    SCENE_MANAGER:RemoveFragment(GAME_CREDITS_FRAGMENT)
end