Thread Tools Display Modes
Prev Previous Post   Next Post Next
06-02-19, 07:18 PM   #1
galvin
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 265
How do I make this options list faster?

To repeat this just download GalvinUnitBars from curse:
https://wow.curseforge.com/projects/.../files/2710572
Then go to general -> Alt Power Bar
Make sure "Show used bars only" is unchecked

The problem is each time I leave this options window and go back. The same lag happens.
I'd like to know how I can speed this up.

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, 10000 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()
                   MyCount = MyCount + 1
                   print(MyCount)
                   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, --]]
        disabled = function()
                     return Main.HasAltPower
                   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 = function()
                   return APBUsed[BarID] == nil and Main.UnitBars.APBShowUsed
                 end,
      }
    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
           --   BuildAltPowerBarList(APA, 100, 'Alternate Power Bar', 'APB')
           --   BuildAltPowerBarList(APA, 101, 'Use Blizzard', 'APBUseBlizz')
            else
              if APA and strfind(KeyName, 'APBDisabled') and Value then
                APA.PowerBarList = nil
              end
              Main.UnitBars[KeyName] = Value
            end
          end,
    disabled = function()
                 if not Main.UnitBars.APBDisabled then
           --        BuildAltPowerBarList(APA, 100, 'Alternate Power Bar', 'APB')
           --        BuildAltPowerBarList(APA, 101, 'Use Blizzard', 'APBUseBlizz')
                 end
                 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 = ''
                 BuildAltPowerBarList(APA, 100, 'Alternate Power Bar', 'APB')
                 BuildAltPowerBarList(APA, 101, 'Use Blizzard', 'APBUseBlizz')
                 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
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » How do I make this options list faster?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off