Quantcast
WoWInterface - View Single Post - How do I make this options list faster?
View Single Post
06-04-19, 12:54 AM   #10
galvin
A Frostmaul Preserver
Join Date: Nov 2006
Posts: 263
Update the code, still runs dog slow on 8.2 PTR, takes around 1 second on live and 15+ on PTR. Fast as I can make it

Code:
local function BuildAltPowerBarList(APA, Order, Name, TableName)
  local APBUsed = Main.APBUsed
  local APBUseBlizz = Main.APBUseBlizz

  local PowerBarList = {
    type = 'group',
    name = Name,
    order = Order,
    args = {},
    disabled = function()
                 return Main.UnitBars.APBDisabled
               end,
  }
  APA[TableName] = PowerBarList
  local PBA = PowerBarList.args

  for BarID = 1, 1000 do
    local AltPowerType, MinPower, _, _, _, _, _, _, _, _, PowerName, PowerTooltip = GetAlternatePowerInfoByID(BarID)
    local ZoneName = APBUsed[BarID]

    if TableName ~= 'APB' then
      if AltPowerType and APBUseBlizz[BarID] then
        local Index = 'APBUseBlizz' .. BarID
        PBA[Index] = APA.APB.args[Index]
      end
    elseif AltPowerType then
      PBA['APBUseBlizz' .. BarID] = {
        type = 'toggle',
        width = 'full',
        arg = BarID,
        name = function()
                 if ZoneName then
                   return format('|cff00ff00%s|r : |cffffff00%s|r (|cff00ffff%s|r)', BarID, PowerName, ZoneName)
                 else
                   return format('|cff00ff00%s|r : |cffffff00%s|r', BarID, PowerName)
                 end
               end,
        order = function()
                  if APBUsed[BarID] then
                    return BarID
                  else
                    return BarID + 1000
                  end
                end,
        hidden = function()
                   local APBShowUsed = Main.UnitBars.APBShowUsed
                   if AltPowerBarSearch == '' or BarID == tonumber(AltPowerBarSearch) or
                                                 strfind(strlower(PowerName),    strlower(AltPowerBarSearch)) or
                                                 strfind(strlower(PowerTooltip), strlower(AltPowerBarSearch)) or
                                                 ZoneName and strfind(strlower(ZoneName), strlower(AltPowerBarSearch)) then
                     if APBShowUsed and APBUsed[BarID] ~= nil then
                       return false
                     elseif not APBShowUsed then
                       return false
                     end
                   end
                   return true
                 end,
      }
      PBA['Line2' .. BarID] = {
        type = 'description',
        name = PowerTooltip,
        fontSize = 'medium',
        order = function()
                  if APBUsed[BarID] then
                    return BarID + 0.2
                  else
                    return BarID + 1000.3
                  end
                end,
        hidden = PBA['APBUseBlizz' .. BarID].hidden,
      }
    end
  end
end

local function CreateAltPowerBarOptions(Order, Name)
  local APA = nil

  local AltPowerBarOptions = {
    type = 'group',
    name = Name,
    order = Order,
    childGroups = 'tab',
    get = function(Info)
            local KeyName = Info[#Info]

            if strfind(KeyName, 'APBUseBlizz') then
              return Main.APBUseBlizz[Info.arg]
            elseif KeyName == 'Search' then
              return AltPowerBarSearch
            else
              return Main.UnitBars[KeyName]
            end
          end,
    set = function(Info, Value)
            local KeyName = Info[#Info]

            if strfind(KeyName, 'APBUseBlizz') then
              Main.APBUseBlizz[Info.arg] = Value
            elseif KeyName == 'Search' then
              AltPowerBarSearch = Value
            else
              Main.UnitBars[KeyName] = Value
            end
          end,
    disabled = function()
                 return Main.HasAltPower
               end,
    args = {
      Description = {
        type = 'description',
        name = 'May take a few seconds to build the list. Bars already used have an area name.\nChecking off a bar will use the blizzard bar instead',
        order = 1,
      },
      Search = {
        type = 'input',
        name = 'Search',
        order = 3,
        disabled = function()
                     return Main.UnitBars.APBDisabled or Main.HasAltPower
                   end,
      },
      clearSearch = {
        type = 'execute',
        name = 'Clear',
        desc = 'Clear search',
        width = 'half',
        order = 4,
        func = function()
                 AltPowerBarSearch = ''
                 HideTooltip(true)
               end,
        disabled = function()
                     return Main.UnitBars.APBDisabled or Main.HasAltPower
                   end,
      },
      APBShowUsed = {
        type = 'toggle',
        name = 'Show used bars only',
        width = 'normal',
        order = 5,
        disabled = function()
                     return Main.UnitBars.APBDisabled or Main.HasAltPower
                   end,
      },
      APBDisabled = {
        type = 'toggle',
        name = 'Disable',
        width = 'half',
        order = 6,
      },
      Spacer10 = CreateSpacer(10),
    },
  }

  APA = AltPowerBarOptions.args
  BuildAltPowerBarList(APA, 100, 'Alternate Power Bar', 'APB')
  BuildAltPowerBarList(APA, 101, 'Use Blizzard', 'APBUseBlizz')

  return AltPowerBarOptions
end

Last edited by galvin : 06-04-19 at 01:00 AM.
  Reply With Quote