Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- display.setStatusBar(display.HiddenStatusBar)
- require( "sqlite3" )
- local widget = require("widget")
- birds = require("Classes.ButtonsBirds") -- THIS HANDLES THE BUTTONS THAT WILL BUILD
- -- THE SQL STATEMENT THAT AGAIN WILL NARROW THE SEARCH.
- --LOCALS FWD
- local composer = require "composer"
- local scene = composer.newScene()
- local path = system.pathForFile( "Birds.sqlite", system.ResourceDirectory )
- local db = sqlite3.open( path )
- local _W, _H = display.contentWidth, display.contentHeight
- local containerGroup = display.newGroup( )
- local dashboardGroup = display.newGroup( )
- local imagePath = "Images/Birds/"
- local bgImage = imagePath .. "bgTheme.jpg"
- local text, themeText, bg, t, count, bgItem, bg, colorConverter, tableView, leftRib, woodPanel, butNext, butBack
- local leftIndent = 50
- local dbTable = {}
- local rowBg = {}
- local rowName = {}
- local rowLatin = {}
- local playButton = {}
- local onRowRender = {}
- local onRowTouch = {}
- local funtionSqlView = {}
- local onSystemEvent = {}
- local colorConverter = {}
- local birdSpec = {}
- --GLOBALS FWD
- mySqlView = {} -- I CHOOSE TO HAVE THIS GLOBAL FOR NOW
- _G.specPool = {}
- _G.catText = "Trykk på en av knappene.."
- updateSql = {}
- -- FUNCTIONS
- function functionSqlView() -- THIS IS THE SQL STATEMENT BUILDER (YOU CAN SEE IN THE TERMINAL)... LAME NAME, I KNOW HAHA
- tableView:deleteAllRows()
- local counter = 1
- local res = {}
- local sep = '"' -- FOR LAZYNESS
- table.insert(res, "SELECT * FROM birds WHERE ")
- for _,v in ipairs(mySqlView) do
- if counter < #mySqlView then
- table.insert( res, (v .. " AND ")) -- I WILL DEAL WITH 'OR' LATER ;D
- else
- table.insert( res, v )
- end
- counter = counter + 1
- end
- sql = sep .. table.concat( res ) .. sep -- CONCATENATES THE WHOLE STATEMEMT STRING
- print("@ 3: functionSqlView builded the sql statememt like this: ", sql)
- --[[ count = 0
- print("Sql in functionSqlView: ", sql)
- for row in db:nrows(sql) do
- count = count +1
- dbTable[count]={}
- dbTable[count].NAME = row.NAME
- dbTable[count].LATIN = row.LATIN
- dbTable[count].INFO = row.INFO
- print("*--inside forloop in functionSqlView--*")
- end
- --]]
- for i = 1, #dbTable do
- local isCategory = false
- local rowHeight = 70
- local rowColor = {
- default = { colorConverter(114, 72, 30, 0) },
- }
- local lineColor = { colorConverter(20, 20, 0, 0) }
- -- Insert the row into the tableView
- tableView:insertRow
- {
- -- isCategory = isCategory,
- rowHeight = rowHeight,
- rowColor = rowColor,
- lineColor = lineColor,
- }
- end
- --tableView:reloadData()
- print("NUM ROWS ", tableView:getNumRows())
- return sql
- end
- function onSystemEvent( event )
- if ( event.type == "applicationExit" ) then
- db:close()
- end
- end
- function colorConverter(r, g, b, a)
- local colorR, colorG, colorB, alphA
- colorR = r/256; colorG = g/256; colorB = b/256
- alphA = a or nil
- return colorR, colorG, colorB, alphA
- end
- function updateCatText()
- if _G.debug == 1 then print("** updateCatText: \n\n") end -- DEBUG
- print(_G.catText)
- if themeText then display.remove( themeText) end
- themeText = display.newText( tostring(_G.catText), 0, 0, _G.msgFont , 34 )
- themeText.anchorX, themeText.anchorY = 0, 0
- themeText.x, themeText.y = leftIndent, (woodPanel.y - woodPanel.height) + 20
- themeText:setFillColor( colorConverter(236, 210, 135, 1) )
- return true
- end
- --[[
- function updateSql(event)
- tableView:deleteAllRows() -- FIRST I LIKE TO REMOVE THE ROWS AND THAT WORKS OF COURSE
- print("Sql in updateSql function is: ", sql)
- for i = 1, #dbTable do
- local isCategory = false
- local rowHeight = 70
- local rowColor = {
- default = { colorConverter(114, 72, 30, 0) },
- }
- local lineColor = { colorConverter(20, 20, 0, 0) }
- -- Insert the row into the tableView
- tableView:insertRow
- {
- -- isCategory = isCategory,
- rowHeight = rowHeight,
- rowColor = rowColor,
- lineColor = lineColor,
- }
- end
- end
- --]]
- function birdSpec(self, event)
- if event.phase == "began" then
- if _G.debug == 1 then print("** birdSpec: \n\n") end -- DEBUG
- _G.specPool.name = self.specName
- _G.specPool.latin = self.specLatin
- _G.specPool.info = self.specInfo
- composer.gotoScene( "playSpecScene" )
- elseif event.phase == "cancelled" or event.phase == "ended" then
- end
- return true
- end
- -- "scene:create()"
- function scene:create( event )
- local sceneGroup = self.view
- if _G.debug == 1 then print("** playGame--scene:create: \n\n") end -- DEBUG
- --Bird.group = Bird.group
- bg = display.newImageRect( bgImage, _W, _H, 375, 667, true )
- bg.anchorX, bg.anchorY = 0, 0
- bg.alpha = 1
- sceneGroup:insert(bg)
- leftRib = display.newImageRect( "leftRib.png", 48, 793, true )
- leftRib.anchorX, leftRib.anchorY = 0, 0
- leftRib.alpha = 1
- sceneGroup:insert(leftRib)
- woodPanel = display.newImageRect( "woodPanel.png", 375, 131, true )
- woodPanel.x, woodPanel.y = display.contentWidth/2, display.contentHeight
- woodPanel.anchorX, woodPanel.anchorY = 0.5, 1
- woodPanel.alpha = 1
- sceneGroup:insert(woodPanel)
- themeText = display.newText( tostring(_G.catText), 0, 0, _G.msgFont , 18 )
- themeText.anchorX, themeText.anchorY = 0, 0
- themeText.x, themeText.y = leftIndent, (woodPanel.y - woodPanel.height) + 30
- themeText:setFillColor( colorConverter(236, 210, 135, 1) )
- sceneGroup:insert(themeText)
- function onRowRender( event )
- local phase = event.phase
- local row = event.row
- if _G.debug == 1 then print("** onRowRender: \n\n") end -- DEBUG
- print("**************** Row rendered", row.id )
- row.bg = display.newRoundedRect( 0, 0, display.contentWidth -48, 50, 12 )
- row.bg.strokeWidth = 0
- row.bg:setFillColor( colorConverter(236, 210, 135, 1) )
- row.bg.alpha = 1
- row.bg.anchorX = 1
- row.bg.anchorY = 0
- row.bg.x = display.contentWidth
- row.bg.y = 10
- row:insert( row.bg )
- row.title = display.newText( row, dbTable[row.index].NAME, 0, 0, _G.msgFont , 24 )
- row.title.x = leftIndent + 10
- row.title.anchorX = 0
- row.title.y = row.contentHeight * 0.15+ row.bg.y
- row.title:setFillColor( colorConverter(114, 72, 30, 1) )
- row.ingress = display.newText( row, dbTable[row.index].LATIN, 0, 0, _G.msgFont , 14 )
- row.ingress.x = leftIndent + 10
- row.ingress.anchorX = 0
- row.ingress.y = row.title.y +20
- row.ingress:setFillColor( colorConverter(114, 72, 30, 1) )
- row.image = display.newImageRect(row, tostring(imagePath .. dbTable[row.index].NAME) .. ".jpg", 45,45 )
- row.image:addEventListener( "touch", row.image)
- row.image.touch = birdSpec
- row.image.anchorX = 1
- row.image.anchorY = 0.25
- row.image.x = display.viewableContentWidth - row.image.width/2
- row.image.y = row.title.y
- -- PARSE VARIABLE TO THE GLOBAL SPECPOOL TABLE
- row.image.specName = dbTable[row.index].NAME
- row.image.specLatin = dbTable[row.index].LATIN
- row.image.specInfo = dbTable[row.index].INFO
- print("**************** Row rendered")
- end
- end
- -- "scene:show()"
- function scene:show( event )
- local sceneGroup = self.view
- local phase = event.phase
- if ( phase == "will" ) then
- if _G.debug == 1 then print("** playGame--scene:show:will: \n\n") end -- DEBUG
- composer.removeHidden( )
- elseif ( phase == "did" ) then
- if _G.debug == 1 then print("** playGame--scene:show:will: \n\n") end -- DEBUG
- --audio.crossFadeBackground( "bgSound.mp3", 1 )
- -- WHEN I FIRE IT UP THE FIRST TIME IT WILL SHOW ALL ENTRIES OF THE DB
- if sql == nil then sql = "SELECT * FROM birds" print("Initiated SQL *") end
- --THE NEXT STATEMENT SIMULATES PUSHING THE BUTTON THAT SELECTS ALL BLACK BIRDS ('Sort' means black in Norwegian)
- --if sql == nil then sql = "SELECT * FROM birds WHERE COLOR1 = 'Sort'" print("Initiated SQL *") end
- count = 0
- print("Sql in playGame: scene show ", sql)
- for row in db:nrows(sql) do
- count = count +1
- dbTable[count]={}
- dbTable[count].NAME = row.NAME
- dbTable[count].LATIN = row.LATIN
- dbTable[count].INFO = row.INFO
- print("*--inside forloop in show:Scene--*")
- end
- tableView = widget.newTableView
- {
- top = 0,
- width = _W+1,
- height = display.contentHeight,
- hideBackground = true,
- isBounceEnabled = true,
- listener = tableViewListener,
- onRowRender = onRowRender,
- }
- for i = 1, #dbTable do
- local isCategory = false
- local rowHeight = 70
- local rowColor = {
- default = { colorConverter(114, 72, 30, 0) },
- }
- local lineColor = { colorConverter(20, 20, 0, 0) }
- -- Insert the row into the tableView
- tableView:insertRow
- {
- -- isCategory = isCategory,
- rowHeight = rowHeight,
- rowColor = rowColor,
- lineColor = lineColor,
- }
- end
- sceneGroup:insert(tableView)
- end
- end
- -- "scene:hide()"
- function scene:hide( event )
- local sceneGroup = self.view
- local phase = event.phase
- if ( phase == "will" ) then
- elseif ( phase == "did" ) then
- if tableView and tableView:getNumRows()>1 then tableView:deleteAllRows()
- print("TableView iterated and deleted from scene hide in playGame")
- end
- _G.catText = ""
- updateCatText()
- end
- end
- function scene:destroy( event )
- local sceneGroup = self.view
- end
- -- Listener setup
- scene:addEventListener( "create", scene )
- scene:addEventListener( "show", scene )
- scene:addEventListener( "hide", scene )
- scene:addEventListener( "destroy", scene )
- return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement