Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.75 KB | None | 0 0
  1. function private:LoadInventoryViewer(container)
  2.     local playerList, guildList = {}, {}
  3.     for name in pairs(TSMAPI.Player:GetCharacters()) do
  4.         playerList[name] = name
  5.         private.inventoryFilters.characters[name] = true
  6.     end
  7.     for name in pairs(TSMAPI.Player:GetGuilds()) do
  8.         guildList[name] = name
  9.         private.inventoryFilters.guilds[name] = true
  10.     end
  11.     private.inventoryFilters.group = nil
  12.  
  13.     local stCols = {
  14.         {
  15.             name = L["Item Name"],
  16.             width = 0.35,
  17.         },
  18.         {
  19.             name = L["Bags"],
  20.             width = 0.08,
  21.             align = "CENTER",
  22.         },
  23.         {
  24.             name = L["Bank"],
  25.             width = 0.08,
  26.             align = "CENTER",
  27.         },
  28.         {
  29.             name = L["Mail"],
  30.             width = 0.08,
  31.             align = "CENTER",
  32.         },
  33.         {
  34.             name = L["GVault"],
  35.             width = 0.08,
  36.             align = "CENTER",
  37.         },
  38.         {
  39.             name = L["AH"],
  40.             width = 0.08,
  41.             align = "CENTER",
  42.         },
  43.         {
  44.             name = L["Total"],
  45.             width = 0.08,
  46.             align = "CENTER",
  47.         },
  48.         {
  49.             name = L["Total Value"],
  50.             width = 0.17,
  51.             align = "RIGHT",
  52.         }
  53.     }
  54.     local stHandlers = {
  55.         OnEnter = function(_, data, self)
  56.             GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  57.             TSMAPI.Util:SafeTooltipLink(data.itemString)
  58.             GameTooltip:Show()
  59.         end,
  60.         OnLeave = function()
  61.             GameTooltip:ClearLines()
  62.             GameTooltip:Hide()
  63.         end
  64.     }
  65.  
  66.     local totalValue = 0
  67.     local playerData, guildData = TSM.Inventory:GetAllData()
  68.     for _, data in pairs(playerData) do
  69.         for itemString, quantity in pairs(data.bag) do
  70.             totalValue = totalValue + (TSMAPI:GetCustomPriceValue(TSM.db.profile.inventoryViewerPriceSource, itemString) or 0) * quantity
  71.         end
  72.         for itemString, quantity in pairs(data.bank) do
  73.             totalValue = totalValue + (TSMAPI:GetCustomPriceValue(TSM.db.profile.inventoryViewerPriceSource, itemString) or 0) * quantity
  74.         end
  75.         for itemString, quantity in pairs(data.reagentBank) do
  76.             totalValue = totalValue + (TSMAPI:GetCustomPriceValue(TSM.db.profile.inventoryViewerPriceSource, itemString) or 0) * quantity
  77.         end
  78.         for itemString, quantity in pairs(data.auction) do
  79.             totalValue = totalValue + (TSMAPI:GetCustomPriceValue(TSM.db.profile.inventoryViewerPriceSource, itemString) or 0) * quantity
  80.         end
  81.         for itemString, quantity in pairs(data.mail) do
  82.             totalValue = totalValue + (TSMAPI:GetCustomPriceValue(TSM.db.profile.inventoryViewerPriceSource, itemString) or 0) * quantity
  83.         end
  84.     end
  85.     for _, data in pairs(guildData) do
  86.         for itemString, quantity in pairs(data) do
  87.             totalValue = totalValue + (TSMAPI:GetCustomPriceValue(TSM.db.profile.inventoryViewerPriceSource, itemString) or 0) * quantity
  88.         end
  89.     end
  90.  
  91.     local page = {
  92.         {
  93.             type = "SimpleGroup",
  94.             layout = "TSMFillList",
  95.             children = {
  96.                 {
  97.                     type = "SimpleGroup",
  98.                     layout = "Flow",
  99.                     children = {
  100.                         {
  101.                             type = "EditBox",
  102.                             label = L["Item Search"],
  103.                             relativeWidth = 0.2,
  104.                             onTextChanged = true,
  105.                             callback = function(_, _, value)
  106.                                 private.inventoryFilters.name = value:trim()
  107.                                 private:UpdateInventoryViewerST()
  108.                             end,
  109.                         },
  110.                         {
  111.                             type = "GroupBox",
  112.                             label = L["Group"],
  113.                             relativeWidth = 0.2,
  114.                             callback = function(_, _, value)
  115.                                 private.inventoryFilters.group = value
  116.                                 private:UpdateInventoryViewerST()
  117.                             end,
  118.                         },
  119.                         {
  120.                             type = "Dropdown",
  121.                             label = L["Characters"],
  122.                             relativeWidth = 0.2,
  123.                             list = playerList,
  124.                             value = private.inventoryFilters.characters,
  125.                             multiselect = true,
  126.                             callback = function(_, _, key, value)
  127.                                 private.inventoryFilters.characters[key] = value
  128.                                 private:UpdateInventoryViewerST()
  129.                             end,
  130.                         },
  131.                         {
  132.                             type = "Dropdown",
  133.                             label = L["Guilds"],
  134.                             relativeWidth = 0.2,
  135.                             list = guildList,
  136.                             value = private.inventoryFilters.guilds,
  137.                             multiselect = true,
  138.                             callback = function(_, _, key, value)
  139.                                 private.inventoryFilters.guilds[key] = value
  140.                                 private:UpdateInventoryViewerST()
  141.                             end,
  142.                         },
  143.                         {
  144.                             type = "EditBox",
  145.                             label = L["Value Price Source"],
  146.                             relativeWidth = 0.2,
  147.                             acceptCustom = true,
  148.                             settingInfo = {TSM.db.profile, "inventoryViewerPriceSource"},
  149.                             callback = function() container:Reload() end,
  150.                         },
  151.                         {
  152.                             type = "HeadingLine",
  153.                         },
  154.                         {
  155.                             type = "Label",
  156.                             relativeWidth = 1,
  157.                             text = format(L["The total value of all your items is %s!"], TSMAPI:MoneyToString(totalValue)),
  158.                         },
  159.                     },
  160.                 },
  161.                 {
  162.                     type = "HeadingLine",
  163.                 },
  164.                 {
  165.                     type = "ScrollingTable",
  166.                     tag = "TSM_INVENTORY_VIEWER",
  167.                     colInfo = stCols,
  168.                     handlers = stHandlers,
  169.                     defaultSort = 1,
  170.                     selectionDisabled = true,
  171.                 },
  172.             },
  173.         },
  174.     }
  175.  
  176.     TSMAPI.GUI:BuildOptions(container, page)
  177.     private:UpdateInventoryViewerST()
  178. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement