lavalevel

Free Cookie Company Lister

Feb 21st, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.28 KB | None | 0 0
  1. --
  2. -- Abstract: List View sample app (showing a background image)
  3. --  
  4. -- Version: 1.0
  5. --
  6. -- Sample code is MIT licensed, see http://developer.anscamobile.com/code/license
  7. -- Copyright (C) 2010 ANSCA Inc. All Rights Reserved.
  8. --
  9. -- Demonstrates how to create a list view using the Table View Library.
  10. -- This example shows the list with a transparent background,
  11. -- allowing an image beneath to show through.
  12.  
  13. --import the table view library
  14. local tableView = require("tableView")
  15.  
  16. --import the button events library
  17. local ui = require("ui")
  18.  
  19. display.setStatusBar( display.HiddenStatusBar )
  20.  
  21. --initial values
  22. local screenOffsetW, screenOffsetH = display.contentWidth -  display.viewableContentWidth, display.contentHeight - display.viewableContentHeight
  23.  
  24. local myList, backBtn, detailScreenText
  25.  
  26. local background = display.newImage("bg.png", true)
  27.  
  28. --setup a destination for the list items
  29. local detailScreen = display.newGroup()
  30.  
  31. detailScreenText = display.newText("You tapped item", 0, 0, native.systemFontBold, 24)
  32. detailScreenText:setTextColor(255, 255, 255)
  33. detailScreen:insert(detailScreenText)
  34. detailScreenText.x = math.floor(display.contentWidth/2)
  35. detailScreenText.y = math.floor(display.contentHeight/2)    
  36. detailScreen.x = display.contentWidth
  37.  
  38. --setup functions to execute on touch of the list view items
  39. function listButtonRelease( event )
  40.     self = event.target
  41.     local id = self.id
  42.     print(self.id)
  43.    
  44.     detailScreenText.text = "You tapped item ".. self.id
  45.            
  46.     transition.to(myList, {time=400, x=display.contentWidth*-1, transition=easing.outExpo })
  47.     transition.to(detailScreen, {time=400, x=0, transition=easing.outExpo })
  48.     transition.to(backBtn, {time=400, x=math.floor(backBtn.width/2) + screenOffsetW*.5 + 6, transition=easing.outExpo })
  49.     transition.to(backBtn, {time=400, alpha=1 })
  50.    
  51.     delta, velocity = 0, 0
  52. end
  53.  
  54. function backBtnRelease( event )
  55.     print("back button released")
  56.     transition.to(myList, {time=400, x=0, transition=easing.outExpo })
  57.     transition.to(detailScreen, {time=400, x=display.contentWidth, transition=easing.outExpo })
  58.     transition.to(backBtn, {time=400, x=math.floor(backBtn.width/2)+backBtn.width, transition=easing.outExpo })
  59.     transition.to(backBtn, {time=400, alpha=0 })
  60.  
  61.     delta, velocity = 0, 0
  62. end
  63.  
  64. local topBoundary = display.screenOriginY + 40
  65. local bottomBoundary = display.screenOriginY + 0
  66. groups = {}
  67. groups['t'] = display.newGroup()
  68. -- setup the data
  69. local data = {}
  70. for i=1, 8 do
  71.     data[i] = "Cookie ".. i
  72. end
  73.  
  74. -- Create a list with no background, allowing the background image to show through
  75. myList = tableView.newList{
  76.     data=data,
  77.     default="listItemBg_white.png",
  78.     over="listItemBg_over.png",
  79.     onRelease=listButtonRelease,
  80.     top=topBoundary,
  81.     bottom=bottomBoundary,
  82.     callback=function(row)
  83.  
  84.         -- local t = display.newGroup()
  85.  
  86.         local img = display.newImage("ListCookie_1.png")
  87.             img.x = math.floor(img.width/2) + 12
  88.             img.y = 46
  89.             groups['t']:insert(img)
  90.  
  91.             local txt = display.newText(row, 0, 0, native.systemFontBold, textSize)
  92.             txt:setTextColor(255, 255, 255)
  93.             txt.x = math.floor(txt.width/2) + 12
  94.             txt.y = 46
  95.  
  96.             groups['t']:insert(txt)
  97.  
  98.  
  99.             return t
  100.         end
  101. }
  102.  
  103.  
  104.  
  105.     elements = {}
  106.     local group = nil
  107.     groups['TheUI'] = display.newGroup()
  108.  
  109.     -- new group
  110.     groups['FPSView'] = display.newGroup()
  111.     groups['TheUI']:insert(groups['FPSView'])
  112.  
  113.     -- new sprite
  114.     elements.FpsWeapon = _spriteFactory:newSpriteGroup("fpsSprite")
  115.     group = elements.FpsWeapon
  116.     groups['FpsWeapon'] = group
  117.     group.elementName = 'FpsWeapon'
  118.     group.libraryName = "fpsSprite"
  119.     groups['FPSView']:insert(group)
  120.     group.x = 0
  121.     group.y = 0
  122.  
  123.     group.xScale = 2
  124.     group.yScale = 2
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. --Setup the nav bar
  134. local navBar = display.newImage("navBar.png", 0, 0, true)
  135. navBar.x = display.contentWidth*.5
  136. navBar.y = math.floor(display.screenOriginY + navBar.height*0.5)
  137.  
  138. local navHeader = display.newText("Free Cookie Company", 0, 0, native.systemFontBold, 16)
  139. navHeader:setTextColor(255, 255, 255)
  140. navHeader.x = display.contentWidth*.5
  141. navHeader.y = navBar.y
  142.  
  143. --Setup the back button
  144. backBtn = ui.newButton{
  145.     default = "backButton.png",
  146.     over = "backButton_over.png",
  147.     onRelease = backBtnRelease
  148. }
  149. backBtn.x = math.floor(backBtn.width/2) + backBtn.width + screenOffsetW
  150. backBtn.y = navBar.y
  151. backBtn.alpha = 0
Add Comment
Please, Sign In to add comment