Advertisement
lavalevel

ScrollView for QuestLister

Aug 6th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.72 KB | None | 0 0
  1. function QuestLister() -- CREATES A LIST OF THE PLAYERS QUESTS
  2.     group.maps.elements.miniMap.isVisible = false
  3.  
  4.     hideGadgets()
  5.  
  6.     if sparkler ~= nil then
  7.         for i=1, #mapNotes do
  8.         sparkler[i].isVisible = false
  9.         sparkler[i]:removeEventListener( "touch", readNote )
  10.         end
  11.     end
  12.     group.maps.elements.BtnMapNotes.isVisible = false
  13.  
  14.     group.maps.elements.Text_Header.text = ( rosetta:getString("Quests") )
  15.     group.maps.elements.Text_Sub1.text = ( " " )
  16.     group.maps.elements.BtnMapReveal.isVisible = false
  17.     group.maps.elements.BtnMapReveal:setEnabled(false, 'up')
  18.    
  19.     group.maps.groups['Spellbook'].isVisible = false
  20.     group.maps.groups['ScrollHandle1'].isVisible = false
  21.     group.maps.groups['ScrollHandle2'].isVisible = false
  22.     group.maps.groups['ScrollMap'].isVisible = true
  23.     group.maps.groups['AtlasMap'].isVisible = false
  24.  
  25.     group.maps.groups['Lists'].isVisible = true
  26.  
  27.     group.maps.elements.btnScroll.isVisible = false
  28.     group.maps.elements.btnScroll:setEnabled(false, 'up')
  29.  
  30.     group.maps.elements.btnWorld.isVisible = false
  31.     group.maps.elements.btnWorld:setEnabled(false, 'up')
  32.  
  33.     group.maps.elements.btnQuests.isVisible = false
  34.     group.maps.elements.btnQuests:setEnabled(false, 'up')
  35.  
  36.     group.maps.elements.btnSpellbook.isVisible = false
  37.     group.maps.elements.btnSpellbook:setEnabled(false, 'up')
  38.  
  39.     group.maps.elements.btnLeft.onTap = returnToGameFromList
  40.  
  41.     local questNames = {}
  42.    
  43.     if #playerData.playerQuests > 0 then -- if the player has any quests complete or active...
  44.         for i= 1, #playerData.playerQuests do
  45.         questLookUp = {}
  46.         local questToInsert = {}
  47.         -- local questLookUp = ( rosetta:getString( QuestLordQuests[ (playerData.playerQuests[i].QuestID) ].QuestName ) )
  48.        
  49.         local name = QuestLordQuests[ (playerData.playerQuests[i].QuestID) ].QuestName
  50.         local completion = playerData.playerQuests[i].QuestCompletion
  51.        
  52.         questNames[i] = { name=name, completion=completion }
  53.         end
  54.  
  55.         --print ("here")
  56.         --atrace (xinspect(questNames))
  57.         --print ("There")
  58.     else -- if the player doesnt have any quest at all
  59.     group.maps.elements.Text_Header.text = ( rosetta:getString("No quests...") )
  60.     group.maps.elements.Text_Sub1.text = ( rosetta:getString("Search for quests.") )
  61.     end
  62.  
  63.     local tableView = require("tableView")
  64.  
  65. --initial values
  66.     local screenOffsetW, screenOffsetH = display.contentWidth -  display.viewableContentWidth, display.contentHeight - display.viewableContentHeight
  67.     local myList
  68.  
  69. -- you might want to move this to layout
  70.     local backgroundBox = display.newRect(1, 1, 320, 412)
  71.     backgroundBox:setFillColor(tonumber("27", 16), tonumber("27", 16), tonumber("27", 16))
  72.     group.maps.groups['Lists']:insert( backgroundBox )
  73.  
  74. --setup functions to execute on touch of the list view items
  75.     function listButtonRelease( event )
  76.         local function returnToList()
  77.             group.maps.elements.btnYes.isVisible = false
  78.             --print "remove self on return to LIST"
  79.             textBox:removeSelf()
  80.             textBox=nil
  81.              scrollView:removeSelf()
  82.             myList.isVisible = true
  83.            
  84.             group.maps.elements.Text_Header.text = ( rosetta:getString("Quests") )
  85.             group.maps.elements.Text_Sub1.text = ( " " )
  86.         end
  87.  
  88.         myList.isVisible = false -- get rid of the list
  89.         -- add a description of what the quest is...
  90.         self = event.target
  91.         local id = self.id
  92.  
  93.         -- TextBoxBackground = false
  94.         textBox = display.newText( ( rosetta:getString ( QuestLordQuests[ (playerData.playerQuests[self.id].QuestID) ].QuestDescription ) ), 4, 9, 320 , 0, "QuadratSerial", 22)
  95.         textBox:setTextColor( 220, 220, 220, 255 )
  96.         local widget = require "widget-V1"
  97.         scrollView = widget.newScrollView{ height=280, maskFile="TextMaskLarge.png", bgColor = {20,20,35,255} } -- 180
  98.         scrollView.isHitTestMasked = true
  99.         scrollView:insert(textBox)
  100.         scrollView.y = 80
  101.  
  102. --      --print ("THIS THING:" .. QuestLordQuests[ (playerData.playerQuests[self.id]) ].QuestDescription)
  103.         textBox.hasBackground = false
  104.  
  105.         group.maps.elements.btnYes.isVisible = true
  106.         group.maps.elements.btnYes.onTap = returnToList
  107.         group.maps.elements.Text_Header.text = ( rosetta:getString(QuestLordQuests[ (playerData.playerQuests[self.id].QuestID) ].QuestName) )  
  108.         --print ("*************************************************")
  109.         --print ("QuestIDCOMPLETION=" .. playerData.playerQuests[self.id].QuestCompletion )
  110.         --print ("QuestIDCONDITION=" .. playerData.playerQuests[self.id].QuestCondition )
  111.         --print ("*************************************************")
  112.         if playerData.playerQuests[self.id].QuestCompletion == "true" then
  113.             group.maps.elements.Text_Sub1.text = ( rosetta:getString("Completed!") )
  114.  
  115.         elseif playerData.playerQuests[self.id].QuestCompletion == "false" then
  116.             group.maps.elements.Text_Sub1.text = ( rosetta:getString("Quest in progress") )
  117.        
  118.         elseif playerData.playerQuests[self.id].QuestCompletion == "return" and playerData.playerQuests[self.id].QuestCondition == "slay" then
  119.             group.maps.elements.Text_Sub1.text = ( rosetta:getString("Return with news of victory!") )
  120.  
  121.  
  122.         elseif playerData.playerQuests[self.id].QuestCompletion == "return" and playerData.playerQuests[self.id].QuestCondition == "retrieve" then
  123.             group.maps.elements.Text_Sub1.text = ( rosetta:getString("Return with Quest Item!") )
  124.         end
  125.  
  126.     end
  127.  
  128. -- setup the data
  129.     local data = questNames
  130.     local topBoundary = display.screenOriginY + 48
  131.     local bottomBoundary = display.screenOriginY +68
  132.  
  133.  
  134. -- Create a list with no backgroundIMG, allowing the backgroundIMG image to show through
  135.    
  136.     --atrace (xinspect(data))
  137.     myList = tableView.newList{
  138.     data=data,
  139.     default="huge_button_up.png",
  140.     over="huge_button_down.png",
  141.     onRelease=listButtonRelease,
  142.     top=topBoundary,
  143.     bottom=bottomBoundary,
  144.     callback=function(row)
  145.  
  146.         local t = display.newGroup()
  147.         local obj
  148.        
  149.         --local obj = display.newImage( "Quest_InProgress.png" )
  150.         if row.completion =="true" then
  151.             obj=display.newImage( "Quest_Complete.png" )
  152.         else                  
  153.             obj=display.newImage( "Quest_InProgress.png" )
  154.         end
  155.  
  156.         local txt = display.newText(row.name, 0, 0, native.systemFontBold, 18)
  157.         txt:setTextColor(255, 255, 255)
  158.         txt.x = math.floor(txt.width/2) + 82
  159.         txt.y = 46
  160.         obj.x = 50
  161.         obj.y = 40
  162.         t:insert(txt)
  163.         t:insert(obj)
  164.  
  165.         return t
  166.         end
  167.     }
  168.  
  169.     --atrace (xinspect(myList))
  170.  
  171.     group.maps.groups['Lists']:insert(myList)
  172.     group.maps.groups['ScrollHandle1'].isVisible = false
  173.     group.maps.groups['ScrollHandle2'].isVisible = false
  174.     group.maps.groups['ScrollMap'].isVisible = false
  175.     group.maps.groups['AtlasMap'].isVisible = false
  176.  
  177.     group.maps.groups['Lists'].isVisible = true
  178.     group.maps.elements.btnQuests.isVisible = false
  179.     group.maps.elements.btnSpellbook.isVisible = false
  180.     group.maps.elements.btnLeft:toFront()
  181.     group.maps.elements.btnQuests.isVisible = false
  182.     group.maps.elements.btnWorld.isVisible = false
  183.  
  184. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement