-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.lua
276 lines (200 loc) · 7.26 KB
/
menu.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
--local composer = require( "composer" )
mouseHover = require "plugin.mouseHover"
local anim = require("scripts.AnimData")
local buttonManager = require("scripts.buttonManager")
local btnMngr = nil
-- local btnMngr = {}
local background = display.newGroup()
local midground = display.newGroup() --this will overlay 'farBackground'
local foreground = display.newGroup()
local UILayer = display.newGroup()
local playButton
local scene = composer.newScene()
currentLevel = 1
-- composer.getScene( "game" )
-- composer.getScene( "levelSelect" )
-- composer.getScene( "credits" )
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
-- local myHoverListener = function(event)
-- print("hover")
-- if event.phase == "began" then
-- -- respond to the hover event here
-- print(event.phase, event.target, event.x, event.y)
-- end
--
-- if event.phase == "ended" then
-- -- respond to the hover event here
-- print(event.phase, event.target, event.x, event.y)
-- end
--
-- end
function setTextToContinue()
playButton.text = localisationManager.continue
btnMngr.originalText = playButton.text
end
local function gotoGame()
timer.performWithDelay( 500 , setTextToContinue)
composer.gotoScene( "game" ,changeSceneOptions )
end
local function gotoLevelSelect()
composer.gotoScene( "levelSelect" ,changeSceneOptions )
end
local function gotoCredits()
composer.gotoScene( "credits" ,changeSceneOptions)
end
--local function
function onKeyEvent(event)
if (event.phase=="up") then
return false
end
-- if not menuOverlayVisible then
if ( event.keyName == "up" ) then
btnMngr:getPrevButton()
elseif event.keyName == "down" then
btnMngr:getNextButton()
end
-- end
if ( event.keyName == "enter" ) then
print ("enter")
-- get btn from current button
btnMngr:pressButton()
end
-- print("check escape menu")
-- if ( event.keyName == "escape" ) then
-- resumeGame()
-- end
-- If the "back" key was pressed on Android or Windows Phone, prevent it from backing out of the app
if ( event.keyName == "back" ) then
local platformName = system.getInfo( "platformName" )
-- composer.gotoScene( "menu" )
if ( platformName == "Android" ) or ( platformName == "WinPhone" ) then
return true
end
end
-- IMPORTANT! Return false to indicate that this app is NOT overriding the received key
-- This lets the operating system execute its default handling of the key
return false
end
local function quitGame()
native.requestExit()
end
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create( event )
Runtime:addEventListener( "key", onKeyEvent )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
--local background = display.newImageRect( sceneGroup, "textures/story1.png", 140, 60 )
local background = display.newSprite(sceneGroup, anim.imageSheetTemple,anim.sequences_temple)
background:play()
background.x = display.contentCenterX
background.y = display.contentCenterY
background.xScale = display.contentHeight/70
background.yScale = display.contentHeight/70
-- background.xScale = 1.5
-- background.yScale = 1.5
-- local title = display.newImageRect( sceneGroup, "title.png", 500, 80 )
-- title.x = display.contentCenterX
-- title.y = 200
-- for i=0,5,1 do
-- local menuButton = display.newImageRect(sceneGroup,"textures/menuButton.png",80,11)
-- menuButton.xScale = 15
-- menuButton.yScale = 15
-- menuButton.x = display.contentWidth+100
-- menuButton.y = 350 + 200*i
-- print (display.contentHeight)
-- print(i)
-- end
local logo = display.newImageRect( sceneGroup, "textures/logo.png", 140, 60 )
-- logo.x = display.contentCenterX
-- logo.y = display.contentCenterY
-- logo.xScale = display.contentHeight/100
-- logo.yScale = display.contentHeight/100
logo.xScale = 8
logo.yScale = 8
logo.x = display.contentWidth+100
logo.y = 300
local yOffsetParent = 350
local yOffset = 165
local textOptions = {
parent = sceneGroup,
text = localisationManager.play, --"Play",
x = display.contentWidth+100,
y = yOffset*1 + yOffsetParent,
font = native.systemFont,
fontSize = textSize*scale,
-- width = 1200,
-- height = 150,
align = "center"
}
playButton = display.newText( textOptions )
textOptions.text = localisationManager.levelSelect
textOptions.y = 2*yOffset + yOffsetParent
local lvlSelectButton = display.newText( textOptions )
textOptions.text = localisationManager.credits
textOptions.y = 3* yOffset + yOffsetParent
local creditBtn = display.newText( textOptions )
textOptions.text = localisationManager.quit
textOptions.y = 4* yOffset + yOffsetParent
local quitBtn = display.newText( textOptions )
playButton.command = gotoGame
lvlSelectButton.command = gotoLevelSelect
creditBtn.command = gotoCredits
quitBtn.command = quitGame
local buttons = {playButton,lvlSelectButton,creditBtn,quitBtn}
btnMngr = buttonManager:create(buttons)
--set currentlevel based on save data
currentLevel = saveManager:getLastActiveLevel() + 1
if currentLevel~=1 then setTextToContinue() end
print ("should load level")
print (currentLevel)
end
-- show()
function scene:show( event )
-- composer.removeScene("menu_overlay")
-- composer.hideOverlay("menu_overlay")
composer.hideOverlay( "menu_overlay" )
Runtime:removeEventListener( "key", onKeyEvent )
Runtime:addEventListener( "key", onKeyEvent )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
print ("show menu")
btnMngr:resume()
end
end
-- hide()
function scene:hide( event )
Runtime:removeEventListener( "key", onKeyEvent )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
print ("hide menu")
btnMngr:pause()
end
end
-- destroy()
function scene:destroy( event )
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return scene