-
Notifications
You must be signed in to change notification settings - Fork 0
/
DPOY.lua
180 lines (140 loc) · 5.63 KB
/
DPOY.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
-----------------------------------------------------------------------------------------
--
-- DPOY.lua
-- The list of all DPOY winners.
--
-----------------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-----------------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
--
-- NOTE: Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
-----------------------------------------------------------------------------------------
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
-- This is a placeholder needed to work around a bug in the Storyboard API.
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
local widget = require "widget"
currentScene = "DPOY";
local listOptions = {
top = 44,
height = 386,
maskFile = "mask-386.png";
}
theList = 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
-- Decompact the id field to determine whichPlayer's page to navigate to.
local t
t = split(event.target.id);
whichPlayer = t[1]
-- Go to a particular player page
storyboard.gotoScene( "player_page" );
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
-- Decompact id field to get the row's information.
local t
t = split(event.target.id);
local year = t[2]
local compYear = year .. "-" .. computeNextSeason(year);
local name = t[3]
local textDate = display.newRetinaText( compYear, 18, 0, "Helvetica-Bold", 18 )
textDate:setReferencePoint( display.CenterLeftReferencePoint )
textDate.y = row.height * 0.5
local textName = display.newRetinaText(name, 18, 0, "Helvetica-Bold", 18);
textName:setReferencePoint( display.CenterLeftReferencePoint )
textName.y = row.height * 0.5
if not row.isCategory then
textDate.x = 10
textDate:setTextColor( 100 )
textName.x = 120 ;
textName:setTextColor(0);
end
-- Must insert everything into event.view: (tableView requirement)
rowGroup:insert( textDate )
rowGroup:insert(textName);
end
-- Create a row for each player in the DPOY list
local playerFirstName;
local playerLastName;
local ilkid;
local year;
local id;
-- Go through the list of DPOYs and create a row for each
for row in db:nrows("SELECT * FROM records_DPOY ORDER BY year DESC") do
playerFirstName = row.firstname;
playerLastName = row.lastname;
ilkid = row.ilkid;
year = row.year;
id = ilkid .. "," .. year.. "," .. playerFirstName .. " " .. playerLastName;
theList: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("Defensive Player / Year");
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
theList:removeSelf()
theList = nil
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