Advertisement
lavalevel

Enter Name, playerName text field

May 23rd, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1.     local function enterName()
  2.  
  3.         print (" ENTER NAME ")
  4.         print (" SAVEDISK:" .. FinalOverWriteDisk)
  5.         group.mm.elements.Text_header.text = ( rosetta:getString("Enter a name") )
  6.  
  7.         group.mm.groups.Text_1.isVisible = false
  8.         group.mm.groups.Text_2.isVisible = false
  9.  
  10.         group.mm.groups['GarbageGroup'].isVisible = false
  11.         group.mm.groups['DiskManager1'].isVisible = false
  12.         group.mm.groups['DiskManager2'].isVisible = false
  13.         group.mm.groups['DiskManager3'].isVisible = false
  14.         group.mm.groups['YesNo'].isVisible = false
  15.         -- string:sub(1, 14)
  16.  
  17.         -- s:sub(1, 14):gsub([[\]], [[\]])
  18.  
  19.         local ui = require("ui")
  20.         -------------------------------------------
  21.         -- General event handler for fields
  22.         -------------------------------------------
  23.         -- You could also assign different handlers for each textfield
  24.  
  25.         local defaultField
  26.         local fields = display.newGroup()
  27.  
  28.         local function fieldHandler( event )
  29.  
  30.             if ( "began" == event.phase ) then
  31.                 -- This is the "keyboard has appeared" event
  32.                 -- In some cases you may want to adjust the interface when the keyboard appears.
  33.            
  34.             elseif ( "ended" == event.phase ) then
  35.                 -- This event is called when the user stops editing a field: for example, when they touch a different field
  36.            
  37.             elseif ( "submitted" == event.phase ) then
  38.                 -- This event occurs when the user presses the "return" key (if available) on the onscreen keyboard
  39.             -- Hide keyboard
  40.             playerName = defaultField.text
  41.             fields:removeSelf()
  42.             verifyName()
  43.                
  44.             native.setKeyboardFocus( playerName )
  45.             end
  46.         end
  47.         -- Predefine local objects for use later
  48.  
  49.         -------------------------------------------
  50.         -- *** Buttons Presses ***
  51.         -------------------------------------------
  52.         -- Default Button Pressed
  53.         --defaultField:removeSelf()
  54.         -- fields:remove( defaultField )
  55.  
  56.         -- Number Button Pressed
  57.         ------------------------------------------
  58.         -- *** Create native input textfields ***
  59.         -------------------------------------------
  60.         -- Note: currently this feature works in device builds or Xcode simulator builds only
  61.  
  62.         -- Note: currently this feature works in device builds only
  63.         local isAndroid = "Android" == system.getInfo("platformName")
  64.         local inputFontSize = 18
  65.         local inputFontHeight = 30
  66.         if isAndroid then
  67.             -- Android text fields have more chrome. It's either make them bigger, or make the font smaller.
  68.             -- We'll do both
  69.             inputFontSize = 14
  70.             inputFontHeight = 42
  71.         end
  72.         defaultField = native.newTextField( 10, 80, 300, 30, fieldHandler )
  73.         defaultField.font = native.newFont( native.systemFontBold, inputFontSize )
  74.         defaultField.align = "center"
  75.         -- Add fields to our new group
  76.         fields:insert(defaultField)
  77.  
  78.         local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
  79.         bkgd:setFillColor( 0, 0, 0, 0 )     -- set Alpha = 0 so it doesn't cover up our buttons/fields
  80.     end
  81.  
  82.  
  83.     local function AlertOverWrite()
  84.  
  85.         -- Handler that gets notified when the alert closes
  86.         -- print ("WARNING FOR SAVEDISK:" .. disk2overwrite)
  87.         local function onComplete( event )
  88.             print( "index => ".. event.index .. "    action => " .. event.action )
  89.      
  90.             local action = event.action
  91.             if "clicked" == event.action then
  92.                     if 1 == event.index then
  93.                             -- Open url if "Learn More" was clicked by the user
  94.                             NewGame()
  95.                             FinalOverWriteDisk = 0
  96.                     end
  97.                     if 2 == event.index then
  98.                             -- Open url if "Learn More" was clicked by the user
  99.                             enterName()
  100.                     end
  101.             --elseif "cancelled" == event.action then
  102.             end
  103.         end
  104.  
  105.  
  106.         local alert = native.showAlert( rosetta:getString("Overwrite?"), rosetta:getString("This Save Will Be Erased!"), { rosetta:getString("No"), rosetta:getString("Yes") }, onComplete )
  107.  
  108.  
  109.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement