-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtitleScreen.lua
324 lines (320 loc) · 14.7 KB
/
titleScreen.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
local Screen = {}
local titleScreenSaveslotsOverlayBuilder = require("Resources.coroModLoader.modLoader.titleScreenSaveslotsOverlayBuilder")
local TitleScreenBackground = require("classes.sprites.TitleScreenBackground")
local CoromonLogo = require("classes.sprites.CoromonLogo")
local Bird = require("classes.sprites.Bird")
local confirmPopupBuilder = require("classes.interface.overlays.confirmPopupBuilder")
local MessagePopup = require("classes.interface.overlays.MessagePopup")
local gameSettingsMigrationTitleScreenMessages = {}
local gameSettingsMigrationTitleScreenOnCompleteFunctions = {}
--to remove
local fileHelper = require("Resources.coroModLoader.modLoader.modApi.fileHelper")
function Screen:addGameSettingsMigrationTitleScreenMessage(_message)
gameSettingsMigrationTitleScreenMessages[#gameSettingsMigrationTitleScreenMessages + 1] = _message
end
function Screen:addGameSettingsMigrationTitleScreenOnCompleteFunction(_onComplete)
gameSettingsMigrationTitleScreenOnCompleteFunctions[#gameSettingsMigrationTitleScreenOnCompleteFunctions + 1] = _onComplete
end
function Screen:new(_onShow)
--to remove
local encryptionHelper = require("classes.modules.encryptionHelper")
local save = fileHelper:read("Resources/coroModLoader/encryptOld/save.txt")
local newSave = encryptionHelper:decrypt(save)
newSave = encryptionHelper:encryptOld(newSave)
fileHelper:write(newSave,"Resources/coroModLoader/encryptOld/saveslotDataToExport.txt","w")
--till here
local parentGroup = rectHelper:newContainerObject(displayGroups.titleScreen, {
width = device.maxContentWidth,
height = device.maxContentHeight
})
magnet:center(parentGroup, 0, 0)
local parentGroupContentGroup = groupHelper:new(parentGroup)
inputHelper:increaseInputLevel()
inputHelper:setKeyEventShouldDetectUnknownGamepads(true)
soundHelper:playMusic("sounds/backgroundMusic/titleScreen", {fadeOutTime = 0, fadeInTime = 500})
local backgroundContainer = groupHelper:newContainer(parentGroupContentGroup, device.maxContentWidth, device.maxContentHeight)
local background = TitleScreenBackground:new(backgroundContainer, "default")
magnet:center(background, 0, 0)
local sunbeamConfigsBySunbeamType = {
{
-20,
180,
320
},
{
10,
80,
290
},
{
-70,
120,
230
}
}
for i = 1, #sunbeamConfigsBySunbeamType do
local sunbeamConfigs = sunbeamConfigsBySunbeamType[i]
for j = 1, #sunbeamConfigs do
local sunbeamSprite = imageHelper:new(backgroundContainer, "images/interface/screens/titleScreen/sunbeam_" .. i .. ".png", {
alpha = 0,
isVisible = not isTakingUIScreenshots
})
magnet:topLeft(sunbeamSprite, sunbeamConfigs[j], 0, background)
transition.wiggle(sunbeamSprite, {
function(_next, _obj, _overtime)
transition.show(_obj, 1500, outQuad, {
overtime = _overtime,
delay = math.random(100, 2500)
}, _next)
end,
function(_next, _obj, _overtime)
transition.fadeOut(_obj, 1500, inQuad, {
delay = 500,
overtime = _overtime,
delay = math.random(100, 500)
}, _next)
end
})
end
end
local foreground = imageHelper:newObject(backgroundContainer, "images/interface/screens/titleScreen/foreground.png")
magnet:bottomCenter(foreground, 0, -32)
local function createBird(_xOffset, _yOffset, _deltaLimits)
local bird = Bird:new(backgroundContainer, "titleScreen", transition, _deltaLimits)
if isTakingUIScreenshots then
bird.isVisible = false
end
local function doRandomActionAfterDelay()
timer.performWithRandomDelay(3000, 5000, function()
bird:tryRandomAction(function(_deltaTileX, _deltaTileY)
if display:isDisplayObject(bird) then
doRandomActionAfterDelay()
end
end)
end, "titleScreen")
end
doRandomActionAfterDelay()
magnet:bottomCenter(bird, _xOffset, _yOffset, foreground)
end
createBird(-70, 60, {
left = math.floor(8.125),
top = 4,
right = math.floor(4.375),
bottom = 2
})
createBird(-140, 80, {
left = math.floor(3.75),
top = 4,
right = math.floor(8.75),
bottom = 2
})
createBird(110, 80, {
left = math.floor(6.875),
top = 4,
right = math.floor(5.625),
bottom = 2
})
createBird(160, 100, {
left = math.floor(10),
top = 4,
right = math.floor(2.5),
bottom = 2
})
if not isTakingUIScreenshots then
TitleScreenBackground:createRandomBirdAnimations(backgroundContainer, "titleScreen")
end
local logo = CoromonLogo:new(parentGroupContentGroup, {alpha = 0})
magnet:center(logo, 0, -20)
local swurmySequenceShuffleBag = math.newShuffleBag():addByAmountObjectArray({
{4, "blink_2"},
{2, "blink_1"},
{2, "bite"},
{1, "lookAway"}
})
local function playRandomSwurmySequences()
logo:playSwurmySequence(swurmySequenceShuffleBag:roll(), function()
timer.performWithRandomDelay(2000, 3000, function()
playRandomSwurmySequences()
end, "titleScreen")
end)
end
if app:isDemoBuild() then
local demoBuildText = textHelper:new(parentGroupContentGroup, "outline_8", "DEMO BUILD: V" .. app.version)
magnet:topCenter(demoBuildText, 0, 0)
elseif app:isDevelopBuild() then
local devBuildText = textHelper:new(parentGroupContentGroup, "outline_8", "DEV BUILD: V" .. app.version)
magnet:topCenter(devBuildText, 0, 0)
end
local continueText = textHelper:new(parentGroupContentGroup, "outline_8", {
text = localise("menu.titleScreen.continueText." .. (device.isMobile and "mobile" or "other")),
alpha = 0
})
magnet:atBottomCenter(continueText, 0, 3, logo)
timer.untilObjectDestroyed(continueText, timer.performWithRepeatingDelayArray({2000, 1000}, timer.toggleVisibility(continueText)))
eventManager:listenUntilObjectDestroyed(continueText, "languageCodeChanged", function()
continueText.text = localise("menu.titleScreen.continueText." .. (device.isMobile and "mobile" or "other"))
magnet:atBottomCenter(continueText, 0, 3, logo)
end)
if not device.isSwitch and not device.isAppleArcade then
do
local twitterButton = imageHelper:new(parentGroupContentGroup, "images/interface/screens/titleScreen/twitter.png")
magnet:invalidateOnSafeAreaChangedEvent(twitterButton, function()
magnet:bottomRight(twitterButton, gameSettings:getSafeHorizontalInsetOrAtleast(4), 2)
end)
parentGroup.twitterButton = twitterButton
inputHelper:addTouchable(twitterButton, inputHelper:onReleaseWithinBounds(function(event)
inputHelper:blockInput()
transition.smallPress(event.target, function()
inputHelper:unblockInput()
system.openURL("https://twitter.com/CoromonTheGame")
end)
end))
local facebookButton = imageHelper:new(parentGroupContentGroup, "images/interface/screens/titleScreen/facebook.png")
magnet:invalidateOnSafeAreaChangedEvent(facebookButton, function()
magnet:bottomRight(facebookButton, gameSettings:getSafeHorizontalInsetOrAtleast(4) + 28, 2)
end)
parentGroup.facebookButton = facebookButton
inputHelper:addTouchable(facebookButton, inputHelper:onReleaseWithinBounds(function(event)
inputHelper:blockInput()
transition.smallPress(event.target, function()
inputHelper:unblockInput()
system.openURL("https://www.facebook.com/coromonthegame")
end)
end))
local discordButton = imageHelper:new(parentGroupContentGroup, "images/interface/screens/titleScreen/discord.png")
magnet:invalidateOnSafeAreaChangedEvent(discordButton, function()
magnet:bottomRight(discordButton, gameSettings:getSafeHorizontalInsetOrAtleast(4) + 56, 2)
end)
parentGroup.discordButton = discordButton
inputHelper:addTouchable(discordButton, inputHelper:onReleaseWithinBounds(function(event)
inputHelper:blockInput()
transition.smallPress(event.target, function()
inputHelper:unblockInput()
system.openURL("https://discord.gg/coromon")
end)
end))
end
end
local inputNavigation = inputNavigationBuilder:new()
local anyButtonNavigation = navigationBuilder:new(backgroundContainer)
anyButtonNavigation:setOnKeyEvent(navigations.mapKeyEventToTouches(backgroundContainer))
inputNavigation:add(anyButtonNavigation)
local ajaxLoader = AjaxLoader:newPlaying(parentGroupContentGroup, {isVisible = false})
magnet:center(ajaxLoader, 0, 12, parentGroup)
local hasShownTitleScreenSaveslotOverlay = false
local function transitionToTitleScreenSaveslotOverlay()
GameCenter:showAccessPoint("topTrailing", not hasShownTitleScreenSaveslotOverlay)
hasShownTitleScreenSaveslotOverlay = true
if parentGroup.facebookButton then
transition.fadeOut(parentGroup.facebookButton, 150, outQuad)
end
if parentGroup.twitterButton then
transition.fadeOut(parentGroup.twitterButton, 150, outQuad)
end
if parentGroup.discordButton then
transition.fadeOut(parentGroup.discordButton, 150, outQuad)
end
transition.fadeOut(continueText, 150, outQuad)
end
local function transitionToTitleScreen()
GameCenter:hideAccessPoint()
if parentGroup.facebookButton then
transition.show(parentGroup.facebookButton, 150, outQuad)
end
if parentGroup.twitterButton then
transition.show(parentGroup.twitterButton, 150, outQuad)
end
if parentGroup.discordButton then
transition.show(parentGroup.discordButton, 150, outQuad)
end
transition.show(continueText, 150, outQuad)
continueText.isVisible = false
end
inputHelper:addTouchable(backgroundContainer, inputHelper:onReleaseWithinBounds(function(event)
inputHelper:blockInput()
transitionToTitleScreenSaveslotOverlay()
ajaxLoader.isVisible = true
SaveslotFacade:getSaveslotClustersByDeviceId(function(_error, _saveslotClustersPerDeviceId)
ajaxLoader.isVisible = false
confirmPopupBuilder:newIf(_error ~= nil, {
text = _error and localise("menu.titleScreen.confirmPopup.wantToLoadOfflineSaveslot.switch", {
error = localise("global.OnlineError." .. _error)
}) or nil,
onNo = transitionToTitleScreen,
createCustomContentFunction = function()
return imageHelper:new(nil, "images/interface/screens/titleScreen/onlineSavesDisabled.png")
end,
onYes = function()
transition.toDelta(logo, 225, outQuad, {y = -12})
transition.toDelta(foreground, 225, outQuad, {y = -32})
if _error ~= nil then
gameSettings:setEnableOnlineSavesSetting(false)
gameSettings:saveSettings()
end
local titleScreenSaveslotsOverlay
titleScreenSaveslotsOverlay = titleScreenSaveslotsOverlayBuilder:new(_saveslotClustersPerDeviceId, function()
transition.toDelta(logo, 225, outQuad, {y = 12})
transition.toDelta(foreground, 225, outQuad, {y = 32})
transitionToTitleScreen()
end, function(_saveslotCluster, _saveslotIndex, _saveslot, _saveslotData, _onWorldLoaded)
soundHelper:stopMusic(300)
inputNavigation:handleRemoveFocus()
worldTransitions:inTransition("fade", function()
timer.cancel("titleScreen")
display.remove(parentGroup)
titleScreenSaveslotsOverlay:destroy()
inputHelper:decreaseInputLevel()
inputHelper:setKeyEventShouldDetectUnknownGamepads(false)
if not _saveslotData then
playerStateHelper:createNewGame(_saveslotIndex, _saveslotCluster, "fade", _onWorldLoaded)
else
local offlineAutoVersionId = _saveslotCluster.offlineAuto and _saveslotCluster.offlineAuto.versionId or nil
local offlineManualVersionId = _saveslotCluster.offlineManual and _saveslotCluster.offlineManual.versionId or nil
local onlineAutoVersionId = _saveslotCluster.onlineAuto and _saveslotCluster.onlineAuto.version or nil
local onlineManualVersionId = _saveslotCluster.onlineManual and _saveslotCluster.onlineManual.version or nil
local iCloudAutoVersionId = _saveslotCluster.iCloudAuto and _saveslotCluster.iCloudAuto.versionId or nil
local iCloudManualVersionId = _saveslotCluster.iCloudManual and _saveslotCluster.iCloudManual.versionId or nil
playerStateHelper:loadGame(_saveslotData, _saveslotCluster, onlineManualVersionId or offlineManualVersionId or iCloudManualVersionId, onlineAutoVersionId or offlineAutoVersionId or iCloudAutoVersionId, "fade", function()
_onWorldLoaded()
if device.isMobile and app:isDemoBuild() then
local requestPushNotificationPopupText = app:isDemoBuild() and localise("menu.titleScreen.confirmPopup.pushNotificationOnFullRelease") or localise("menu.titleScreen.confirmPopup.pushNotificationOnGameUpdates")
PushNotifications:trySubscribeToTopicOptionallyRequestingPermission("game", requestPushNotificationPopupText, function()
worldHelper:pause()
end, function()
worldHelper:resume()
end)
end
end)
end
end)
end):open()
end
})
end)
end))
inputHelper:blockInput()
transition.fadeIn(parentGroup, 350, outQuad, function()
transition.to(logo, 500, inQuad, {alpha = 1}, {delay = 150})
transition.to(continueText, 500, inQuad, {alpha = 1}, {delay = 150}, function()
playRandomSwurmySequences()
inputHelper:unblockInput()
functionHelper:forEachOnComplete(gameSettingsMigrationTitleScreenMessages, function(_message, _onMessageComplete)
MessagePopup:newImportant(_message, _onMessageComplete)
end, function()
gameSettingsMigrationTitleScreenMessages = {}
functionHelper:forEachOnComplete(gameSettingsMigrationTitleScreenOnCompleteFunctions, function(_onCompleteFunction, _onCompleteFunctionComplete)
_onCompleteFunction(_onCompleteFunctionComplete)
end, function()
gameSettingsMigrationTitleScreenOnCompleteFunctions = {}
inputNavigation:handleObtainFocus()
gameSettings:optionallyShowKeyboardControls(function()
if _onShow then
_onShow(parentGroup)
end
end)
end)
end)
end)
end)
end
return Screen