-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreatureList.lua
More file actions
146 lines (109 loc) · 4.71 KB
/
creatureList.lua
File metadata and controls
146 lines (109 loc) · 4.71 KB
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
local composer = require( "composer" )
local scene = composer.newScene()
require("database")
local widget = require("widget")
-- a scrolling list of creatures, displayed as an overlay.
-- Creatures with a catch count of 0 are blanked / ??? out
-- creatures with a catch count of >0 show their image, name, and total caught of them.
-- possibly a list of where they can be found.
-- -----------------------------------------------------------------------------------
-- 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 mainView = {}
function hideThis()
composer.hideOverlay()
return true
end
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
print("opening list")
local bgFill = {.6, .6, .6, 1}
bg = display.newRect(sceneGroup, display.contentCenterX, display.contentCenterY, 700, 1150)
bg.fill = bgFill
local header = display.newImageRect(sceneGroup, "themables/creatureList.png",300, 100)
header.x = display.contentCenterX
header.y = 150
header:addEventListener("tap", hideThis)
header:toFront()
print("header up")
local imgCredits = display.newText(sceneGroup, "Images CC BY-NC Pheonixsong at https://phoenixdex.alteredorigin.net", 625, 1200, 1200, 0, native.systemFont, 22)
imgCredits.anchorX = .5
imgCredits.anchorY = .5
imgCredits:setFillColor({0, 0, 0})
mainView = widget.newScrollView({ x= display.contentCenterX, y = display.contentCenterY + 20, width = 600, height = 900, horizontalScrollDisabled = true, backgroundColor = {.6, .6, .6}})
mainView.backgroundColor = {1, 1, 0}
print("scroll view exists")
local dbEntries = Query("SELECT name, count FROM creaturesCaught ORDER BY name")
print("got entries")
print(#dbEntries)
local nextX = 100
local nextY = 0
for i, v in ipairs(dbEntries) do
print("in loop")
if v[2] == 0 then
--draw empty entry.
questionMarkLine = display.newText(sceneGroup, "???", nextX + 100, nextY + 60, 200, 0, native.systemFont, 22)
mainView:insert(questionMarkLine)
else
--draw the actual entry
local image = display.newImageRect(sceneGroup, "themables/CreatureImages/" .. v[1] .. ".png", 200, 200)
image.x = nextX + 25
image.y = nextY + 25
image.anchorX = 0.5
image.anchorY = 0
local nameLine = display.newText(sceneGroup, v[1], nextX + 50, nextY + 20 , 200, 0, native.systemFont, 22)
local countInfo = display.newText(sceneGroup, "Total Collected:" .. v[2], nextX + 25, nextY + 220, 200, 0, native.systemFont, 22)
mainView:insert(image)
mainView:insert(nameLine)
mainView:insert(countInfo)
end
--update positioning info.
if i % 2 == 0 then
nextY = nextY + 250
nextX = 100
else
nextX = 400
end
end
end
-- show()
function scene:show( event )
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
end
end
-- hide()
function scene:hide( event )
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)
mainView:removeSelf()
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
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