Advertisement
lavalevel

enterName()

Apr 28th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.78 KB | None | 0 0
  1.     local function enterName()
  2.  
  3.  
  4.        
  5.         -- graphic stuff, ignore this
  6.         print (" ENTER NAME ")
  7.         print (" SAVEDISK:" .. FinalOverWriteDisk)
  8.         group.mm.elements.Text_header.text = ( rosetta:getString("Enter a name") )
  9.  
  10.         group.mm.groups.Text_1.isVisible = false
  11.         group.mm.groups.Text_2.isVisible = false
  12.  
  13.         group.mm.groups['GarbageGroup'].isVisible = false
  14.         group.mm.groups['DiskManager1'].isVisible = false
  15.         group.mm.groups['DiskManager2'].isVisible = false
  16.         group.mm.groups['DiskManager3'].isVisible = false
  17.         group.mm.groups['YesNo'].isVisible = false
  18.  
  19.  
  20.         local ui = require("ui")
  21.        
  22.  
  23.  
  24.         -------------------------------------------
  25.         -- General event handler for fields
  26.         -------------------------------------------
  27.         -- You could also assign different handlers for each textfield
  28.  
  29.        
  30.         local fields = display.newGroup()
  31.  
  32.         local function fieldHandler( event )
  33.  
  34.             if ( "began" == event.phase ) then
  35.                 -- This is the "keyboard has appeared" event
  36.                 -- In some cases you may want to adjust the interface when the keyboard appears.
  37.            
  38.             elseif ( "ended" == event.phase ) then
  39.                 -- This event is called when the user stops editing a field: for example, when they touch a different field
  40.            
  41.             elseif ( "submitted" == event.phase ) then
  42.                 -- This event occurs when the user presses the "return" key (if available) on the onscreen keyboard
  43.             -- Hide keyboard
  44.             playerName = defaultField.text
  45.             fields:removeSelf()
  46.             native.setKeyboardFocus()
  47.  
  48.             -- textField
  49.             --id of the field on which to set the keyboard focus, or nil to hide the keyboard.
  50.             verifyName()
  51.                
  52.                
  53.             end
  54.         end
  55.         -- Predefine local objects for use later
  56.  
  57.         -------------------------------------------
  58.         -- *** Buttons Presses ***
  59.         -------------------------------------------
  60.         -- Default Button Pressed
  61.         --defaultField:removeSelf()
  62.         -- fields:remove( defaultField )
  63.  
  64.         -- Number Button Pressed
  65.         ------------------------------------------
  66.         -- *** Create native input textfields ***
  67.         -------------------------------------------
  68.         -- Note: currently this feature works in device builds or Xcode simulator builds only
  69.  
  70.         -- Note: currently this feature works in device builds only
  71.         local isAndroid = "Android" == system.getInfo("platformName")
  72.         local inputFontSize = 18
  73.         local inputFontHeight = 30
  74.         if isAndroid then
  75.             -- Android text fields have more chrome. It's either make them bigger, or make the font smaller.
  76.             -- We'll do both
  77.             inputFontSize = 14
  78.             inputFontHeight = 42
  79.         end
  80.         defaultField = native.newTextField( 10, 80, 300, 30); defaultField:addEventListener("userInput", fieldHandler)
  81.         defaultField.font = native.newFont( native.systemFontBold, inputFontSize )
  82.         defaultField.align = "center"
  83.         -- Add fields to our new group
  84.         fields:insert(defaultField)
  85.  
  86.         -------------------------------------------
  87.         -- *** Add field labels ***
  88.         -------------------------------------------
  89.  
  90.         -- "Remove Default" Button
  91.         -- Position the buttons on screen
  92.         -- Create a Background touch event
  93.         -------------------------------------------
  94.         local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
  95.         bkgd:setFillColor( 0, 0, 0, 0 )     -- set Alpha = 0 so it doesn't cover up our buttons/fields
  96.         -- Tapping screen dismisses the keyboard
  97.         -- Needed for the Number and Phone textFields since there is
  98.         -- no return key to clear focus.
  99.         local function listener( event )
  100.             -- Hide keyboard
  101.             print("tap pressed")
  102.             native.setKeyboardFocus(fields.defaultField)
  103.             playerName = defaultField.text
  104.             bkgd:removeEventListener("tap", listener)
  105.             bkgd:removeSelf()
  106.            
  107.  
  108.                
  109.         end
  110.         -- Determine if running on Corona Simulator
  111.         -- Add listener to background for user "tap"
  112.         bkgd:addEventListener( "tap", listener )
  113.    
  114.    
  115.     verifyName()
  116.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement