Advertisement
Guest User

infotexts

a guest
Sep 26th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.89 KB | None | 0 0
  1. --
  2. -- TinyMainbarInfo
  3. --
  4. -- by Bastian Pflieger <wb@illogical.de>
  5. --
  6. --
  7. --Credit goes to ^ this guy above. I only edited it and removed some stuff.  ~ Danielps1
  8.  
  9. local FORMAT_COORDS = "%.1f, %.1f"
  10. local FORMAT_NETSTATS = "%.2f KB/S"
  11. local FORMAT_TIME_ONLINE = "%02d:%02d"
  12. local FORMAT_MEMORY_USAGE = "%.3f MB"
  13. local FORMAT_FPS
  14. local FORMAT_LAG = ""
  15. local FORMAT_DURABILITY
  16. local FORMAT_ILEVEL = "%d"
  17. local FORMAT_ILEVEL_COLOR
  18.  
  19. local onlineTime = 0;
  20. local timer = 0;
  21. local doScan, loaded;
  22.  
  23. BINDING_HEADER_TINYMAINBARINFO = "Tiny Mainbar Info";
  24. BINDING_NAME_TINYMAINBARINFO_SWITCH_BAR = "Toggle on / off";
  25.  
  26. --[[ local microButtons = {
  27.     "CharacterMicroButton",
  28.     "SpellbookMicroButton",
  29.     "TalentMicroButton",
  30.     "QuestLogMicroButton",
  31.     "MainMenuMicroButton",
  32.     "PVPMicroButton",
  33.     "SocialsMicroButton",
  34.     "GuildMicroButton", -- Cataclysm
  35.     "GuildMicroButtonTabard",
  36.     "LFDMicroButton",
  37.     "HelpMicroButton",
  38.     "AchievementMicroButton",
  39.     "EJMicroButton", -- 4.2
  40.     "RaidMicroButton", -- 4.2
  41. }
  42. if MICRO_BUTTONS and CopyTable then
  43.     wipe(microButtons)
  44.     microButtons = CopyTable(MICRO_BUTTONS)
  45. end
  46. ]]
  47.  
  48. --[[
  49. Check if we need special handling for MicroButtonPortrait, GuildMicroButtonTabard
  50. Those are the two that have separate events modifying their alpha.
  51. Might need to also hook GuildMicroButton_UpdateTabard() or just add it to the frame list.
  52. ]]
  53.  
  54. local ilevelSlots = {
  55.     (GetInventorySlotInfo("HeadSlot")),
  56.     (GetInventorySlotInfo("NeckSlot")),
  57.     (GetInventorySlotInfo("ShoulderSlot")),
  58.     (GetInventorySlotInfo("BackSlot")),
  59.     (GetInventorySlotInfo("ChestSlot")),
  60.     (GetInventorySlotInfo("WristSlot")),
  61.     (GetInventorySlotInfo("HandsSlot")),
  62.     (GetInventorySlotInfo("WaistSlot")),
  63.     (GetInventorySlotInfo("LegsSlot")),
  64.     (GetInventorySlotInfo("FeetSlot")),
  65.     (GetInventorySlotInfo("Finger0Slot")),
  66.     (GetInventorySlotInfo("Finger1Slot")),
  67.     (GetInventorySlotInfo("Trinket0Slot")),
  68.     (GetInventorySlotInfo("Trinket1Slot")),
  69.     (GetInventorySlotInfo("MainHandSlot")),
  70.     (GetInventorySlotInfo("SecondaryHandSlot")),
  71. --  (GetInventorySlotInfo("RangedSlot"))
  72. }
  73.  
  74.  
  75. local function TinyMainbarInfo_dura()
  76.     local minDura = 100
  77.     for index, value in pairs(INVENTORY_ALERT_STATUS_SLOTS) do
  78.         local cur, maxim = GetInventoryItemDurability(index)
  79.         if cur then
  80.             percent = (cur/maxim) * 100
  81.             minDura = percent < minDura and percent or minDura
  82.         end
  83.     end
  84.     if minDura<25 then
  85.         FORMAT_DURABILITY = RED_FONT_COLOR_CODE.."%d%%"..FONT_COLOR_CODE_CLOSE
  86.     elseif minDura<55 then
  87.         FORMAT_DURABILITY = YELLOW_FONT_COLOR_CODE.."%d%%"..FONT_COLOR_CODE_CLOSE
  88.     else
  89.         FORMAT_DURABILITY = "%d%%"
  90.     end
  91.     return format(FORMAT_DURABILITY,minDura)
  92. end
  93.  
  94. local quality = {}
  95. local function TinyMainBarInfo_iLvl()
  96.     local avgilvl, oldilvl
  97.     wipe(quality)
  98.     local count, total = 0,0
  99.     for i,v in ipairs(ilevelSlots) do
  100.         local id = GetInventoryItemID("player",v)
  101.         if id then
  102.             local n,_,q,ilvl = GetItemInfo(id)
  103.             if n then
  104.                 total = total + ilvl
  105.                 count = count + 1
  106.                 quality[q] = quality[q] and quality[q]+1 or 1
  107.             end
  108.         end
  109.     end
  110.     if total > 0 and count > 0 then
  111.         oldilvl = total/count
  112.     end
  113.     local maj, num = 0,0
  114.     if next(quality) then
  115.         for k,v in pairs(quality) do
  116.             num = v>num and v or num
  117.         end
  118.         for k,v in pairs(quality) do
  119.             if v == num then
  120.                 maj = k
  121.                 break
  122.             end
  123.         end
  124.     end
  125.     if maj then
  126.         FORMAT_ILEVEL_COLOR = ""
  127.     end
  128.     if GetAverageItemLevel then
  129.         local avgilvleq
  130.         avgilvl, avgilvleq = GetAverageItemLevel()
  131.         if avgilvleq then oldilvl = avgilvleq end
  132.     end
  133.     if avgilvl and oldilvl then
  134.         return format(FORMAT_ILEVEL..""..FORMAT_ILEVEL_COLOR.."",avgilvl,oldilvl)
  135.     elseif avgilvl then
  136.         return format(FORMAT_ILEVEL,avgilvl)
  137.     elseif oldilvl then
  138.         return format(FORMAT_ILEVEL_COLOR,oldilvl)
  139.     else
  140.         return "?"
  141.     end
  142. end
  143.  
  144. local function TinyMainbarInfo_modf(num)
  145.   return math.floor(num), num - math.floor(num);
  146. end
  147.  
  148. local function TinyMainbarInfo_OnLoad(self)
  149.  
  150.   self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  151.   self:RegisterEvent("PLAYER_ENTERING_WORLD")
  152.   self:RegisterEvent("PLAYER_MONEY")
  153.   self:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
  154.   self:RegisterEvent("UPDATE_INVENTORY_ALERTS")
  155.   self:RegisterEvent("PLAYER_AVG_ITEM_LEVEL_READY")
  156.     self:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
  157.     self:RegisterEvent("PLAYER_FLAGS_CHANGED")
  158.    
  159.  
  160. end
  161.  
  162. money = math.floor(GetMoney()/10000) .. "g"
  163.  
  164. local function TinyMainbarInfo_OnEvent(self, event, ...)
  165.     if event == "PLAYER_ENTERING_WORLD" then
  166.         -- money, durability, ilvl
  167.         self.moneyText:SetText(money,10)
  168.         self.duraText:SetText(TinyMainbarInfo_dura())
  169.         self.ilvlText:SetText(TinyMainBarInfo_iLvl())
  170.         self:RegisterEvent("BAG_UPDATE")
  171.     elseif event == "UPDATE_INVENTORY_DURABILITY" or event == "UPDATE_INVENTORY_ALERTS" then
  172.         -- durability
  173.         self.duraText:SetText(TinyMainbarInfo_dura())
  174.     elseif event == "PLAYER_AVG_ITEM_LEVEL_READY" or event == "PLAYER_EQUIPMENT_CHANGED" or event == "BAG_UPDATE" then
  175.         -- average ilvl
  176.         doScan = GetTime() -- done in OnUpdate2 when there's 0.5 sec from last request passed.
  177.     elseif event == "PLAYER_MONEY" then
  178.         -- money
  179.         --
  180.         self.moneyText:SetText(money,10)
  181.     elseif event == "PLAYER_FLAGS_CHANGED" then
  182.         -- online time icon (on,away,dnd)
  183.        
  184.     elseif event == "ZONE_CHANGED_NEW_AREA" then
  185.     SetMapToCurrentZone();
  186.   end
  187. end
  188.  
  189. local function TinyMainbarInfo_OnUpdate(self, elapsed)
  190.   onlineTime = onlineTime + elapsed;
  191.   timer = timer + elapsed;
  192. end
  193.  
  194. local function TinyMainbarInfo_OnUpdate2(self, elapsed)
  195.     if doScan and GetTime()>(doScan+0.5) then
  196.         self.ilvlText:SetText(TinyMainBarInfo_iLvl())
  197.     doScan = nil
  198.   end
  199.   if timer > 1 then
  200.     local x, y = GetPlayerMapPosition("player");
  201.     self.coordText:SetText(string.format(FORMAT_COORDS, x * 100, y * 100));
  202.    
  203.     -- Update network flow
  204.     local kbin, kbout, mlatency, wlatency = GetNetStats();
  205.    
  206.    
  207.     if mlatency >= 250 then
  208.         FORMAT_LAG = RED_FONT_COLOR_CODE.."%dms"..FONT_COLOR_CODE_CLOSE;
  209.     elseif mlatency >= 100 then
  210.         FORMAT_LAG = LIGHTYELLOW_FONT_COLOR_CODE.."%dms"..FONT_COLOR_CODE_CLOSE;
  211.     else
  212.         FORMAT_LAG = "%dms";
  213.     end
  214.    
  215.     self.latText:SetText(string.format(FORMAT_LAG, mlatency, wlatency));
  216.    
  217.     -- Update time played this session
  218.     local hours, frac = TinyMainbarInfo_modf(onlineTime / 60 / 60);
  219.     local minutes, frac = TinyMainbarInfo_modf(frac * 60);
  220.     local seconds =   TinyMainbarInfo_modf(frac * 60);
  221.     self.onlineText:SetText(string.format(FORMAT_TIME_ONLINE, hours, minutes));
  222.    
  223.    
  224.     -- Update fps
  225.     local fps = GetFramerate()
  226.     if fps < 15 then
  227.         FORMAT_FPS = RED_FONT_COLOR_CODE.."%.1ffps"..FONT_COLOR_CODE_CLOSE
  228.     elseif fps < 30 then
  229.         FORMAT_FPS = YELLOW_FONT_COLOR_CODE.."%.1ffps"..FONT_COLOR_CODE_CLOSE
  230.     else
  231.         FORMAT_FPS = "%.0ffps"
  232.     end
  233.     self.fpsText:SetText(string.format(FORMAT_FPS, fps));
  234.    
  235.     timer = 0;
  236.   end
  237. end
  238.  
  239. do
  240.     local timeframe = CreateFrame("Frame")
  241.     timeframe:SetScript("OnUpdate", TinyMainbarInfo_OnUpdate)
  242.    
  243.     local f = CreateFrame("Frame","TinyMainbarInfoFrame",MainMenuBarArtFrame)
  244.     f:SetFrameLevel(f:GetParent():GetFrameLevel()+1)
  245.     f:SetScript("OnEvent", TinyMainbarInfo_OnEvent)
  246.     f:SetScript("OnUpdate", TinyMainbarInfo_OnUpdate2)
  247.    
  248.    
  249.     local onlineText = f:CreateFontString(nil,"OVERLAY")
  250.    
  251.     onlineText:SetPoint("CENTER",onlineIcon,"BOTTOMRIGHT",-56,10)
  252.     f.onlineText = onlineText
  253.     f.onlineText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
  254.     f.onlineText:SetTextColor(1,1,1)
  255.    
  256.    
  257.     local coordText = f:CreateFontString(nil,"OVERLAY")
  258.     coordText:SetPoint("CENTER",UIPARENT,"BOTTOMLEFT",55,10)
  259.     f.coordText = coordText
  260.     f.coordText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
  261.     f.coordText:SetTextColor(1,1,1)
  262.    
  263.    
  264.    
  265.    
  266.    
  267.     local duraText = f:CreateFontString(nil,"OVERLAY")
  268.     duraText:SetPoint("CENTER",UIPARENT,"BOTTOMLEFT",292,10)
  269.     f.duraText = duraText
  270.     f.duraText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
  271.     f.duraText:SetTextColor(1,1,1)
  272.    
  273.     local ilvlText = f:CreateFontString(nil,"OVERLAY")
  274.     ilvlText:SetPoint("CENTER",UIPARENT,"BOTTOMLEFT",174.5,10)
  275.     f.ilvlText = ilvlText
  276.     f.ilvlText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
  277.     f.ilvlText:SetTextColor(1,1,1)
  278.  
  279.     local moneyText = f:CreateFontString(nil,"OVERLAY") -- middle column
  280. --  moneyText:SetPoint("TOP",MainMenuBarTexture2,"TOP",60,-4)
  281.     moneyText:SetPoint("CENTER",UIPARENT,"BOTTOMLEFT",409.5,10)
  282.     f.moneyText = moneyText
  283.     f.moneyText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
  284.     f.moneyText:SetTextColor(1,1,1)
  285.  
  286.     local latText = f:CreateFontString(nil,"OVERLAY")
  287.     latText:SetPoint("CENTER",UIPARENT,"BOTTOMRIGHT",-291,10)
  288.     f.latText = latText
  289.     f.latText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
  290.     f.latText:SetTextColor(1,1,1)
  291.  
  292.    
  293.     local fpsText = f:CreateFontString(nil,"OVERLAY") -- right column
  294. --  fpsText:SetPoint("TOPRIGHT",MainMenuBarTexture2,"TOPRIGHT",70,-4)
  295.     fpsText:SetPoint("CENTER",UIPARENT,"BOTTOMRIGHT",-175,10)
  296.     f.fpsText = fpsText
  297.     f.fpsText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
  298.     f.fpsText:SetTextColor(1,1,1)
  299.    
  300.     --[[ local memText = f:CreateFontString(nil,"OVERLAY")
  301.     memText:SetPoint("BOTTOMRIGHT",UIPARENT,"BOTTOMRIGHT",-50,5)
  302.     f.memText = memText
  303.     f.memText:SetFontObject("GameFontNormalSmall")
  304.     f.memText:SetTextColor(1,1,1)
  305.     ]]
  306.    
  307.     --[[ local netText = f:CreateFontString(nil,"OVERLAY")
  308.     netText:SetPoint("TOPRIGHT",memText,"BOTTOMRIGHT",0,-3)
  309.     f.netText = netText
  310.     f.netText:SetFontObject("GameFontNormalSmall")
  311.     f.netText:SetTextColor(1,1,1) ]]
  312.    
  313.     TinyMainbarInfo_OnLoad(f)
  314.    
  315. end
  316.  
  317. --[[
  318. text = GetCoinTextureString(money)
  319. tableitemids = GetInventoryItemsForSlot(slot)
  320. isdnd = UnitIsDND(unit)
  321. isafk = UnitIsAFK(unit)
  322. slot, texture = GetInventorySlotInfo(slotName)
  323. current, max = GetInventoryItemDurability(slot)
  324. isbroken = GetInventoryItemBroken(unit,slot)
  325. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement