ESO Lua File v100010

app/loadingscreen/loadingscreen.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
local EvtMgr = GetEventManager()
local g_animation
local TEXTURE_WIDTH = 1680
local TEXTURE_HEIGHT = 1050
local TEXTURE_ASPECT_RATIO = TEXTURE_WIDTH / TEXTURE_HEIGHT
local LOADING_TIP_PERCENTAGE = 0.8
local INSTANCE_DISPLAY_TYPE_ICONS =
{
    [INSTANCE_DISPLAY_TYPE_SOLO] = "EsoUI/Art/loadingTips/loadingTip_soloInstance.dds",
    [INSTANCE_DISPLAY_TYPE_GROUP] = "EsoUI/Art/loadingTips/loadingTip_groupInstance.dds",
    [INSTANCE_DISPLAY_TYPE_RAID] = "EsoUI/Art/loadingTips/loadingTip_raidDungeon.dds",
    [INSTANCE_DISPLAY_TYPE_GROUP_DELVE] = "EsoUI/Art/loadingTips/loadingTip_groupDelve.dds",
}
function GetInstanceDisplayTypeIcon(instanceType)
    return INSTANCE_DISPLAY_TYPE_ICONS[instanceType]
end
local function SizeLoadingTexture()
    local screenWidth, screenHeight = GuiRoot:GetDimensions()
    local screenAspectRatio = screenWidth / screenHeight
    if TEXTURE_ASPECT_RATIO > screenAspectRatio then
        local scale = screenHeight / TEXTURE_HEIGHT 
        LoadingScreenArt:SetDimensions(TEXTURE_WIDTH * scale, screenHeight)
    else
        local scale = screenWidth / TEXTURE_WIDTH
        LoadingScreenArt:SetDimensions(screenWidth, TEXTURE_HEIGHT * scale)
    end
end
do
    local RANDOM_TEXTURE_COUNT = 9
    
    local function GetRandomLoadingTexture()
        local textureIndex = math.random(1, RANDOM_TEXTURE_COUNT)
        return string.format("esoui/art/loadingscreens/charload_%02d.dds", textureIndex)
    end
    local seenZones = {}
    ShowLoadingScreen = function(zoneName, zoneDescription, loadingTexture, instanceType, useInstanceTypeFormat)
        SizeLoadingTexture()
        local isDefaultTexture = "" == loadingTexture
        if(isDefaultTexture) then
            loadingTexture = GetRandomLoadingTexture()
        end
        LoadingScreenArt:SetTexture(loadingTexture)
        LoadingScreenZoneInfoContainerZoneName:SetHidden(isDefaultTexture)
        LoadingScreenZoneDescription:SetHidden(isDefaultTexture)
        local showInstanceType = instanceType ~= INSTANCE_DISPLAY_TYPE_NONE
        LoadingScreenZoneInfoContainerInstanceTypeIcon:SetHidden(not showInstanceType)
        LoadingScreenZoneInfoContainerInstanceType:SetHidden(not showInstanceType)
        if not isDefaultTexture and GetGuiHidden("app") then
              if(showInstanceType) then
                    LoadingScreenZoneInfoContainerInstanceTypeIcon:SetTexture(GetInstanceDisplayTypeIcon(instanceType))
                    LoadingScreenZoneInfoContainerInstanceType:SetText(GetString("SI_INSTANCEDISPLAYTYPE", instanceType))
               end
               LoadingScreenZoneInfoContainerZoneName:SetText(LocalizeString("<<C:1>>", zoneName))
            if seenZones[zoneName] and math.random() <= LOADING_TIP_PERCENTAGE then
                local tip = GetLoadingTip()
                if(tip ~= "") then
                    LoadingScreenZoneDescription:SetText(tip)
                else
                    LoadingScreenZoneDescription:SetText(LocalizeString("<<1>>", zoneDescription))
                end
            else
                LoadingScreenZoneDescription:SetText(LocalizeString("<<1>>", zoneDescription))
            end
            seenZones[zoneName] = true
        end
        SetGuiHidden("app", false)
        g_animation:PlayForward()
    end
end
local function HideLoadingScreen()
    g_animation:PlayBackward()
end
local function OnLoadingCompleted()
end
local function OnAreaLoadStarted(evt, area, instance, zoneName, zoneDescription, loadingTexture, instanceType)     
    ShowLoadingScreen(zoneName, zoneDescription, loadingTexture, instanceType)
end
local function OnPrepareForJump(evt, zoneName, zoneDescription, loadingTexture, instanceType)
    ShowLoadingScreen(zoneName, zoneDescription, loadingTexture, instanceType)
end
local function OnJumpFailed()
end
do
    local g_keyEdgefileFreeList = {}
    local g_keyEdgefileActiveList = {}
    local function GetOrCreateKeyEdgefile()
        local keyEdgeFile = next(g_keyEdgefileFreeList) or GetWindowManager():CreateControlFromVirtual("", LoadingScreenZoneDescription, "ZO_LoadingScreen_KeyBackdrop")
        g_keyEdgefileFreeList[keyEdgeFile] = nil
        g_keyEdgefileActiveList[keyEdgeFile] = true
        return keyEdgeFile
    end
    local function ReleaseAll()
        for keyEdgeFile in pairs(g_keyEdgefileActiveList) do
            g_keyEdgefileActiveList[keyEdgeFile] = nil
            g_keyEdgefileFreeList[keyEdgeFile] = true
            keyEdgeFile:SetHidden(true)
        end
    end
    function ZO_LoadingScreenZoneDesc_OnNewUserAreaCreated(self, areaData, areaText, left, right, top, bottom)
        if areaData == "key" then
            local keyEdgeFile = GetOrCreateKeyEdgefile()
            keyEdgeFile:SetAnchor(TOPLEFT, self, TOPLEFT, left + 2, top - 1)
            keyEdgeFile:SetAnchor(BOTTOMRIGHT, self, TOPLEFT, right - 2, bottom + 1)
            keyEdgeFile:SetHidden(false)
        end
    end
        ReleaseAll()
    end
end
do
    local TARGET_FRAMERATE = 60
    local MAX_FRAMES_PER_UPDATE = 5
    local g_currentRotation = 0
    local g_lastUpdate = GetFrameTimeMilliseconds()
    local MAX_ROTATION = math.pi * 2
    local ROTATION_PER_FRAME = -math.pi * .02
    function OnUpdate()
        local now = GetFrameTimeMilliseconds()
        local delta = now - g_lastUpdate
        local numFramesToIncrease = delta / TARGET_FRAMERATE
        if numFramesToIncrease == 0 then
            return
        elseif numFramesToIncrease > MAX_FRAMES_PER_UPDATE then
            numFramesToIncrease = MAX_FRAMES_PER_UPDATE
        end
        g_lastUpdate = now
        g_currentRotation = (g_currentRotation + numFramesToIncrease * ROTATION_PER_FRAME) % MAX_ROTATION
        LoadingScreenAnimation:SetTextureRotation(g_currentRotation)
    end
end
function InitLoadScreen(self)
    EvtMgr:RegisterForEvent("LoadingScreen", EVENT_AREA_LOAD_STARTED, OnAreaLoadStarted)
    EvtMgr:RegisterForEvent("LoadingScreen", EVENT_SCREEN_RESIZED, SizeLoadingTexture)
    EvtMgr:RegisterForEvent("LoadingScreen", EVENT_PREPARE_FOR_JUMP, OnPrepareForJump)
    EvtMgr:RegisterForEvent("LoadingScreen", EVENT_JUMP_FAILED, OnJumpFailed)
    g_animation = GetAnimationManager():CreateTimelineFromVirtual("LoadingCompleteAnimation")
    g_animation:GetAnimation(1):SetAnimatedControl(LoadingScreenArt)
    g_animation:GetAnimation(2):SetAnimatedControl(LoadingScreenBg)
    g_animation:GetAnimation(3):SetAnimatedControl(LoadingScreenTopMunge)
    g_animation:GetAnimation(4):SetAnimatedControl(LoadingScreenTopMunge)
    g_animation:GetAnimation(5):SetAnimatedControl(LoadingScreenBottomMunge)
    g_animation:GetAnimation(6):SetAnimatedControl(LoadingScreenBottomMunge)
    g_animation:GetAnimation(7):SetAnimatedControl(LoadingScreenAnimation)
    local function OnSubsystemLoadComplete(eventCode, system)
        if GetNumTotalSubsystemsToLoad() == GetNumLoadedSubsystems() then
            OnLoadingCompleted()
        end
    end
    EvtMgr:RegisterForEvent("LoadingScreen", EVENT_SUBSYSTEM_LOAD_COMPLETE, OnSubsystemLoadComplete)
end