Advertisement
Guest User

ZO_ScrollList

a guest
Jan 24th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.56 KB | None | 0 0
  1.  
  2. -- Temporarily used for my button to toggle through categories
  3. local currentId = 1
  4.  
  5. local ROW_TYPE_ID               = 1
  6.  
  7. local CATEGORY_WAYSHRINES       = 1
  8. local CATEGORY_DUNGEON          = 2
  9. local CATEGORY_DUNGEON_GROUP    = 3
  10. local CATEGORY_OTHER            = 4
  11. local CATEGORY_LOCATIONS        = 5
  12.  
  13. local tCategoryNames = {
  14.     [CATEGORY_WAYSHRINES]       = "WayShrines",
  15.     [CATEGORY_DUNGEON]          = "Dungeons",
  16.     [CATEGORY_DUNGEON_GROUP]    = "Group Dungeons",
  17.     [CATEGORY_OTHER]            = "Other",
  18.     [CATEGORY_LOCATIONS]        = "Locations",
  19. }
  20.  
  21. -- Sets a Waypoint
  22. function TweakIt.SetWaypoint(self)
  23.     local data = self.dataEntry.data
  24.     d("ping")
  25.     PingMap(MAP_PIN_TYPE_PLAYER_WAYPOINT, MAP_TYPE_LOCATION_CENTERED, data.normalizedX, data.normalizedZ)
  26. end
  27.  
  28. -- Gets a table of data about all POI's & Locations on the current map
  29. local function GetPOIData()
  30.     SetMapToPlayerLocation()
  31.     local iZoneIndex = GetCurrentMapZoneIndex()
  32.     local iNumPOIS = GetNumPOIs(iZoneIndex)
  33.     local tData = {}
  34.    
  35.     local iNumLocations = GetNumMapLocations()
  36.     for iLoc = 1, iNumLocations do
  37.         local iCurTableIndex = #tData+1
  38.         tData[iCurTableIndex] = {
  39.             categoryId      = CATEGORY_LOCATIONS,
  40.             normalizedX     = normalizedX,
  41.             normalizedZ     = normalizedZ,
  42.             objectiveName   = objectiveName,
  43.             objectiveLevel  = objectiveLevel,
  44.             startDescript   = startDescription,
  45.             finishDescript  = finishedDescription,
  46.             iconPath        = icon,
  47.         }
  48.         local icon, normalizedX,  normalizedZ = GetMapLocationIcon(iLoc)
  49.         local name = GetMapLocationTooltipHeader(iLoc)
  50.         tData[iCurTableIndex].iconPath = icon
  51.         tData[iCurTableIndex].normalizedX = normalizedX
  52.         tData[iCurTableIndex].normalizedZ = normalizedZ
  53.         tData[iCurTableIndex].objectiveName = name
  54.     end
  55.    
  56.     for iPoiIndex=1, iNumPOIS do
  57.         local iCurTableIndex = #tData+1
  58.         local playerMapName = GetPlayerLocationName()
  59.        
  60.         local objectiveName, objectiveLevel, startDescription, finishedDescription = GetPOIInfo(iZoneIndex, iPoiIndex)
  61.         local normalizedX, normalizedZ, poiType, icon = GetPOIMapInfo(iZoneIndex, iPoiIndex)
  62.         --d("iZoneIndex: "..tostring(iZoneIndex)..", iPoiIndex: "..tostring(iPoiIndex)..", objectiveName: "..tostring(objectiveName))
  63.        
  64.         tData[iCurTableIndex] = {
  65.             categoryId      = nil,
  66.             normalizedX     = normalizedX,
  67.             normalizedZ     = normalizedZ,
  68.             objectiveName   = objectiveName,
  69.             objectiveLevel  = objectiveLevel,
  70.             startDescript   = startDescription,
  71.             finishDescript  = finishedDescription,
  72.             iconPath        = icon,
  73.             zoneIndex       = iZoneIndex,
  74.             poiIndex        = iPoiIndex,
  75.         }
  76.         if IsPOIWayshrine(iZoneIndex, iPoiIndex) then
  77.             tData[iCurTableIndex].categoryId = CATEGORY_WAYSHRINES
  78.         elseif IsPOIPublicDungeon(iZoneIndex, iPoiIndex) then
  79.             tData[iCurTableIndex].categoryId  = CATEGORY_DUNGEON
  80.         elseif IsPOIGroupDungeon(iZoneIndex, iPoiIndex) then
  81.             tData[iCurTableIndex].categoryId  = CATEGORY_DUNGEON_GROUP
  82.         else
  83.             tData[iCurTableIndex].categoryId  = CATEGORY_OTHER
  84.         end
  85.     end
  86.    
  87.     -- Sort it alphabetically
  88.     table.sort(tData,
  89.         function(bvalue1, bvalue2)
  90.             if bvalue1.objectiveName < bvalue2.objectiveName then
  91.                 return true
  92.             end
  93.         end)
  94.     return tData
  95. end
  96.  
  97. -- Called to update all waypoint POI's & Locations
  98. function TweakIt.UpdateWaypointWindow()
  99.     local tlw = TweakItScrollList
  100.     local dataList = ZO_ScrollList_GetDataList(tlw)
  101.     local data = GetPOIData()
  102.     ZO_ScrollList_Clear(tlw)
  103.    
  104.     -- Whenever you clear the scrollList it clears the categories, must re-add them
  105.     ZO_ScrollList_AddCategory(tlw, CATEGORY_WAYSHRINES, nil)
  106.     ZO_ScrollList_AddCategory(tlw, CATEGORY_DUNGEON, nil)
  107.     ZO_ScrollList_AddCategory(tlw, CATEGORY_DUNGEON_GROUP, nil)
  108.     ZO_ScrollList_AddCategory(tlw, CATEGORY_OTHER, nil)
  109.     ZO_ScrollList_AddCategory(tlw, CATEGORY_LOCATIONS, nil)
  110.    
  111.     for i=1, #data do
  112.         --function ZO_ScrollList_CreateDataEntry(typeId, data, categoryId)
  113.         local entry = ZO_ScrollList_CreateDataEntry(ROW_TYPE_ID, data[i], data[i].categoryId)
  114.         table.insert(dataList, entry)
  115.         --dataList[#dataList+1] = entry
  116.     end
  117.     ZO_ScrollList_Commit(tlw)
  118. end
  119.  
  120. -- This is called by a test button I made to toggle through the categories to test it
  121. local function ShowCategoryId(_iCategoryId)
  122.     -- toggle through categories, just to test with
  123.     currentId = (currentId+1)%6
  124.     d("showing id: "..currentId)
  125.     ZO_ScrollList_HideAllCategories(TweakItScrollList)
  126.     ZO_ScrollList_ShowCategory(TweakItScrollList, currentId)
  127.    
  128.     TweakItWaypointLabel:SetText(tCategoryNames[currentId])
  129.     --ZO_ScrollList_RefreshVisible(TweakItScrollList)
  130. end
  131.  
  132. -- Creates the actual waypoint window
  133. -- ha yah tlw1 & tlw...confusing, I need to rename stuff & clean it up.
  134. function TweakIt.CreateWaypointsWindow()
  135.     local tlw1 = WINDOW_MANAGER:CreateTopLevelWindow("TweakItTLW")
  136.     tlw1:ClearAnchors()
  137.     tlw1:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, 100,100)
  138.     tlw1:SetDimensions(300, 600)
  139.     tlw1:SetMouseEnabled(true)
  140.     tlw1:SetMovable(true)
  141.     tlw1:SetClampedToScreen(true)
  142.    
  143.     tlw1.bg = WINDOW_MANAGER:CreateControlFromVirtual("TweakItTLWBg", tlw1, "ZO_DefaultBackdrop")
  144.     tlw1.bg:ClearAnchors()
  145.     tlw1.bg:SetAnchorFill()
  146.    
  147.     local tlw = WINDOW_MANAGER:CreateControlFromVirtual("TweakItScrollList", tlw1, "ZO_ScrollList")
  148.     tlw:ClearAnchors()
  149.     tlw:SetAnchor(TOPLEFT, tlw1, TOPLEFT, 0, 40)
  150.     tlw:SetDimensions(300, 560)
  151.     tlw:SetClampedToScreen(true)
  152.    
  153.     local function setupCallback(rowControl, data, scrollList)
  154.         local icon = rowControl:GetNamedChild("Texture")
  155.         local label = rowControl:GetNamedChild("Label")
  156.         rowControl.iconPath = data.iconPath
  157.        
  158.         icon:SetTexture(data.iconPath)
  159.         label:SetText(data.objectiveName)
  160.     end
  161.     local function dataTypeSelectSound()
  162.         --PlaySound(SOUNDS.ITEM_MONEY_CHANGED)
  163.     end
  164.    
  165.     --function ZO_ScrollList_AddDataType(self, typeId, templateName, height, setupCallback, hideCallback, dataTypeSelectSound, resetControlCallback)    
  166.     ZO_ScrollList_AddDataType(tlw, ROW_TYPE_ID, "WayPointButton", 70, setupCallback, hideCallback, dataTypeSelectSound, resetControlCallback)  
  167.    
  168.     btn = WINDOW_MANAGER:CreateControlFromVirtual("TweakItWaypointsBtn1", tlw, "ZO_BladeHeader")
  169.     btn:SetDimensions(300, 25)
  170.     btn:SetDrawLevel(1)
  171.     btn:SetDrawLayer(1)
  172.     btn:SetDrawTier(1)
  173.     btn:SetClickSound("Click")
  174.     btn:ClearAnchors()
  175.     btn:SetAnchor(TOPLEFT, _cAnchorWin, BOTTOMLEFT, 0, 0)
  176.     btn:SetHidden(false)
  177.     btn:SetHandler("OnClicked", function() ShowCategoryId() end)
  178.    
  179.     local cLabel = WINDOW_MANAGER:CreateControl("TweakItWaypointLabel", tlw1, CT_LABEL)
  180.     cLabel:ClearAnchors()
  181.     cLabel:SetAnchor(TOPLEFT, tlw1, TOPLEFT, 0, -20)
  182.     cLabel:SetAnchor(BOTTOMRIGHT, tlw1, TOPRIGHT, 0, 0)
  183.     cLabel:SetFont("ZoFontWinH4")
  184.     cLabel:SetText("None")
  185.    
  186.     -- After its created update the current POI's & Locations
  187.     TweakIt.UpdateWaypointWindow()
  188. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement