-
Notifications
You must be signed in to change notification settings - Fork 0
/
records.lua
executable file
·170 lines (131 loc) · 5.76 KB
/
records.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
-----------------------------------------------------------------------------------------
--
-- records.lua
-- The view that appears when the 'awards' tab bar button is clicked. A list of each
-- award or record available for view (e.g. ROY, MVP, etc.)
--
-----------------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local recordsArray = { "Most Valuable Player", "League Champions", "Rookie of the Year", "Defensive Player of the Year", "Sixth Man Award" };
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
local blah = display.newRetinaText( "blah", 18, 0, "Helvetica-Bold", 12 )
group:insert( blah )
blah.isVisible = false;
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
--list.isVisible = true;
currentScene = "records";
local listOptions = {
top = 44,
height = 386,
maskFile = "mask-386.png";
}
local widget = require "widget"
list = widget.newTableView( listOptions )
-- onEvent listener for the tableView
local function onRowTouch( event )
local row = event.target
local rowGroup = event.view
if event.phase == "press" then
if not row.isCategory then rowGroup.alpha = 0.5;
end
elseif event.phase == "release" then
if not row.isCategory then
updateHistory(currentScene);
-- reRender property tells row to refresh if still onScreen when content moves
row.reRender = true
print( "You touched row #" .. event.index )
--set the global variable that lets the program know which letter is being viewed.
whichRecord = event.target.id;
--go to the applicable record's page
if (event.target.id == "Most Valuable Player") then
storyboard.gotoScene( "MVP" );
end
if (event.target.id == "Rookie of the Year") then
storyboard.gotoScene( "ROY" );
end
if (event.target.id == "Defensive Player of the Year") then
storyboard.gotoScene( "DPOY" );
end
if (event.target.id == "Sixth Man Award") then
storyboard.gotoScene( "6man" );
end
if (event.target.id == "League Champions") then
storyboard.gotoScene( "champions" );
end
end
end
return true
end
-- onRender listener for the tableView that renders each row.
local function onRowRender( event )
local row = event.target
local rowGroup = event.view
local text = display.newRetinaText( event.target.id, 18, 0, "Helvetica-Bold", 18 )
text:setReferencePoint( display.CenterLeftReferencePoint )
text.y = row.height * 0.5
if not row.isCategory then
text.x = 15
text:setTextColor( 0 )
end
-- must insert everything into event.view (tableView requirement)
rowGroup:insert( text )
end
-- Create a row manually for each entry.
for j=1,5 do
local rowHeight, rowColor, lineColor, isCategory, id
rowHeight = 40;
id = recordsArray[j];
-- Function below is responsible for creating the row
list:insertRow{
onEvent=onRowTouch,
id=id,
onRender=onRowRender,
height=rowHeight,
isCategory=isCategory,
rowColor=rowColor,
lineColor=lineColor
}
end
-- All objects must be added to group (e.g. self.view) but are not in this case since widgets act problematically with group.insert
-- group:insert( list )
-- group:insert( title )
-- Create the NavBar with the appropriate title
createNavBar("Awards");
displayBackButton();
--insert everything into the group to be changed on scene changes
group:insert(navBar);
group:insert(navHeader);
group:insert( backButton )
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
--lastScene = "teams";
list:removeSelf()
list = nil
--list.isVisible = false;
end
function scene:destroyScene( event )
local group = self.view
end
-----------------------------------------------------------------------------------------
-- Do not touch below: Listeners required for Storyboard API.
-----------------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched whenever before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-----------------------------------------------------------------------------------------
return scene