Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- TinyMainbarInfo
- --
- -- by Bastian Pflieger <[email protected]>
- --
- --
- --Credit goes to ^ this guy above. I only edited it and removed some stuff. ~ Danielps1
- local FORMAT_COORDS = "%.1f, %.1f"
- local FORMAT_NETSTATS = "%.2f KB/S"
- local FORMAT_TIME_ONLINE = "%02d:%02d"
- local FORMAT_MEMORY_USAGE = "%.3f MB"
- local FORMAT_FPS
- local FORMAT_LAG = ""
- local FORMAT_DURABILITY
- local FORMAT_ILEVEL = "%d"
- local FORMAT_ILEVEL_COLOR
- local onlineTime = 0;
- local timer = 0;
- local doScan, loaded;
- BINDING_HEADER_TINYMAINBARINFO = "Tiny Mainbar Info";
- BINDING_NAME_TINYMAINBARINFO_SWITCH_BAR = "Toggle on / off";
- --[[ local microButtons = {
- "CharacterMicroButton",
- "SpellbookMicroButton",
- "TalentMicroButton",
- "QuestLogMicroButton",
- "MainMenuMicroButton",
- "PVPMicroButton",
- "SocialsMicroButton",
- "GuildMicroButton", -- Cataclysm
- "GuildMicroButtonTabard",
- "LFDMicroButton",
- "HelpMicroButton",
- "AchievementMicroButton",
- "EJMicroButton", -- 4.2
- "RaidMicroButton", -- 4.2
- }
- if MICRO_BUTTONS and CopyTable then
- wipe(microButtons)
- microButtons = CopyTable(MICRO_BUTTONS)
- end
- ]]
- --[[
- Check if we need special handling for MicroButtonPortrait, GuildMicroButtonTabard
- Those are the two that have separate events modifying their alpha.
- Might need to also hook GuildMicroButton_UpdateTabard() or just add it to the frame list.
- ]]
- local ilevelSlots = {
- (GetInventorySlotInfo("HeadSlot")),
- (GetInventorySlotInfo("NeckSlot")),
- (GetInventorySlotInfo("ShoulderSlot")),
- (GetInventorySlotInfo("BackSlot")),
- (GetInventorySlotInfo("ChestSlot")),
- (GetInventorySlotInfo("WristSlot")),
- (GetInventorySlotInfo("HandsSlot")),
- (GetInventorySlotInfo("WaistSlot")),
- (GetInventorySlotInfo("LegsSlot")),
- (GetInventorySlotInfo("FeetSlot")),
- (GetInventorySlotInfo("Finger0Slot")),
- (GetInventorySlotInfo("Finger1Slot")),
- (GetInventorySlotInfo("Trinket0Slot")),
- (GetInventorySlotInfo("Trinket1Slot")),
- (GetInventorySlotInfo("MainHandSlot")),
- (GetInventorySlotInfo("SecondaryHandSlot")),
- -- (GetInventorySlotInfo("RangedSlot"))
- }
- local function TinyMainbarInfo_dura()
- local minDura = 100
- for index, value in pairs(INVENTORY_ALERT_STATUS_SLOTS) do
- local cur, maxim = GetInventoryItemDurability(index)
- if cur then
- percent = (cur/maxim) * 100
- minDura = percent < minDura and percent or minDura
- end
- end
- if minDura<25 then
- FORMAT_DURABILITY = RED_FONT_COLOR_CODE.."%d%%"..FONT_COLOR_CODE_CLOSE
- elseif minDura<55 then
- FORMAT_DURABILITY = YELLOW_FONT_COLOR_CODE.."%d%%"..FONT_COLOR_CODE_CLOSE
- else
- FORMAT_DURABILITY = "%d%%"
- end
- return format(FORMAT_DURABILITY,minDura)
- end
- local quality = {}
- local function TinyMainBarInfo_iLvl()
- local avgilvl, oldilvl
- wipe(quality)
- local count, total = 0,0
- for i,v in ipairs(ilevelSlots) do
- local id = GetInventoryItemID("player",v)
- if id then
- local n,_,q,ilvl = GetItemInfo(id)
- if n then
- total = total + ilvl
- count = count + 1
- quality[q] = quality[q] and quality[q]+1 or 1
- end
- end
- end
- if total > 0 and count > 0 then
- oldilvl = total/count
- end
- local maj, num = 0,0
- if next(quality) then
- for k,v in pairs(quality) do
- num = v>num and v or num
- end
- for k,v in pairs(quality) do
- if v == num then
- maj = k
- break
- end
- end
- end
- if maj then
- FORMAT_ILEVEL_COLOR = ""
- end
- if GetAverageItemLevel then
- local avgilvleq
- avgilvl, avgilvleq = GetAverageItemLevel()
- if avgilvleq then oldilvl = avgilvleq end
- end
- if avgilvl and oldilvl then
- return format(FORMAT_ILEVEL..""..FORMAT_ILEVEL_COLOR.."",avgilvl,oldilvl)
- elseif avgilvl then
- return format(FORMAT_ILEVEL,avgilvl)
- elseif oldilvl then
- return format(FORMAT_ILEVEL_COLOR,oldilvl)
- else
- return "?"
- end
- end
- local function TinyMainbarInfo_modf(num)
- return math.floor(num), num - math.floor(num);
- end
- local function TinyMainbarInfo_OnLoad(self)
- self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
- self:RegisterEvent("PLAYER_ENTERING_WORLD")
- self:RegisterEvent("PLAYER_MONEY")
- self:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
- self:RegisterEvent("UPDATE_INVENTORY_ALERTS")
- self:RegisterEvent("PLAYER_AVG_ITEM_LEVEL_READY")
- self:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
- self:RegisterEvent("PLAYER_FLAGS_CHANGED")
- end
- money = math.floor(GetMoney()/10000) .. "g"
- local function TinyMainbarInfo_OnEvent(self, event, ...)
- if event == "PLAYER_ENTERING_WORLD" then
- -- money, durability, ilvl
- self.moneyText:SetText(money,10)
- self.duraText:SetText(TinyMainbarInfo_dura())
- self.ilvlText:SetText(TinyMainBarInfo_iLvl())
- self:RegisterEvent("BAG_UPDATE")
- elseif event == "UPDATE_INVENTORY_DURABILITY" or event == "UPDATE_INVENTORY_ALERTS" then
- -- durability
- self.duraText:SetText(TinyMainbarInfo_dura())
- elseif event == "PLAYER_AVG_ITEM_LEVEL_READY" or event == "PLAYER_EQUIPMENT_CHANGED" or event == "BAG_UPDATE" then
- -- average ilvl
- doScan = GetTime() -- done in OnUpdate2 when there's 0.5 sec from last request passed.
- elseif event == "PLAYER_MONEY" then
- -- money
- --
- self.moneyText:SetText(money,10)
- elseif event == "PLAYER_FLAGS_CHANGED" then
- -- online time icon (on,away,dnd)
- elseif event == "ZONE_CHANGED_NEW_AREA" then
- SetMapToCurrentZone();
- end
- end
- local function TinyMainbarInfo_OnUpdate(self, elapsed)
- onlineTime = onlineTime + elapsed;
- timer = timer + elapsed;
- end
- local function TinyMainbarInfo_OnUpdate2(self, elapsed)
- if doScan and GetTime()>(doScan+0.5) then
- self.ilvlText:SetText(TinyMainBarInfo_iLvl())
- doScan = nil
- end
- if timer > 1 then
- local x, y = GetPlayerMapPosition("player");
- self.coordText:SetText(string.format(FORMAT_COORDS, x * 100, y * 100));
- -- Update network flow
- local kbin, kbout, mlatency, wlatency = GetNetStats();
- if mlatency >= 250 then
- FORMAT_LAG = RED_FONT_COLOR_CODE.."%dms"..FONT_COLOR_CODE_CLOSE;
- elseif mlatency >= 100 then
- FORMAT_LAG = LIGHTYELLOW_FONT_COLOR_CODE.."%dms"..FONT_COLOR_CODE_CLOSE;
- else
- FORMAT_LAG = "%dms";
- end
- self.latText:SetText(string.format(FORMAT_LAG, mlatency, wlatency));
- -- Update time played this session
- local hours, frac = TinyMainbarInfo_modf(onlineTime / 60 / 60);
- local minutes, frac = TinyMainbarInfo_modf(frac * 60);
- local seconds = TinyMainbarInfo_modf(frac * 60);
- self.onlineText:SetText(string.format(FORMAT_TIME_ONLINE, hours, minutes));
- -- Update fps
- local fps = GetFramerate()
- if fps < 15 then
- FORMAT_FPS = RED_FONT_COLOR_CODE.."%.1ffps"..FONT_COLOR_CODE_CLOSE
- elseif fps < 30 then
- FORMAT_FPS = YELLOW_FONT_COLOR_CODE.."%.1ffps"..FONT_COLOR_CODE_CLOSE
- else
- FORMAT_FPS = "%.0ffps"
- end
- self.fpsText:SetText(string.format(FORMAT_FPS, fps));
- timer = 0;
- end
- end
- do
- local timeframe = CreateFrame("Frame")
- timeframe:SetScript("OnUpdate", TinyMainbarInfo_OnUpdate)
- local f = CreateFrame("Frame","TinyMainbarInfoFrame",MainMenuBarArtFrame)
- f:SetFrameLevel(f:GetParent():GetFrameLevel()+1)
- f:SetScript("OnEvent", TinyMainbarInfo_OnEvent)
- f:SetScript("OnUpdate", TinyMainbarInfo_OnUpdate2)
- local onlineText = f:CreateFontString(nil,"OVERLAY")
- onlineText:SetPoint("CENTER",onlineIcon,"BOTTOMRIGHT",-56,10)
- f.onlineText = onlineText
- f.onlineText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
- f.onlineText:SetTextColor(1,1,1)
- local coordText = f:CreateFontString(nil,"OVERLAY")
- coordText:SetPoint("CENTER",UIPARENT,"BOTTOMLEFT",55,10)
- f.coordText = coordText
- f.coordText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
- f.coordText:SetTextColor(1,1,1)
- local duraText = f:CreateFontString(nil,"OVERLAY")
- duraText:SetPoint("CENTER",UIPARENT,"BOTTOMLEFT",292,10)
- f.duraText = duraText
- f.duraText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
- f.duraText:SetTextColor(1,1,1)
- local ilvlText = f:CreateFontString(nil,"OVERLAY")
- ilvlText:SetPoint("CENTER",UIPARENT,"BOTTOMLEFT",174.5,10)
- f.ilvlText = ilvlText
- f.ilvlText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
- f.ilvlText:SetTextColor(1,1,1)
- local moneyText = f:CreateFontString(nil,"OVERLAY") -- middle column
- -- moneyText:SetPoint("TOP",MainMenuBarTexture2,"TOP",60,-4)
- moneyText:SetPoint("CENTER",UIPARENT,"BOTTOMLEFT",409.5,10)
- f.moneyText = moneyText
- f.moneyText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
- f.moneyText:SetTextColor(1,1,1)
- local latText = f:CreateFontString(nil,"OVERLAY")
- latText:SetPoint("CENTER",UIPARENT,"BOTTOMRIGHT",-291,10)
- f.latText = latText
- f.latText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
- f.latText:SetTextColor(1,1,1)
- local fpsText = f:CreateFontString(nil,"OVERLAY") -- right column
- -- fpsText:SetPoint("TOPRIGHT",MainMenuBarTexture2,"TOPRIGHT",70,-4)
- fpsText:SetPoint("CENTER",UIPARENT,"BOTTOMRIGHT",-175,10)
- f.fpsText = fpsText
- f.fpsText:SetFont("Interface\\Addons\\WrathsUI\\media\\fonts\\roboto.ttf", 11,'NONE')
- f.fpsText:SetTextColor(1,1,1)
- --[[ local memText = f:CreateFontString(nil,"OVERLAY")
- memText:SetPoint("BOTTOMRIGHT",UIPARENT,"BOTTOMRIGHT",-50,5)
- f.memText = memText
- f.memText:SetFontObject("GameFontNormalSmall")
- f.memText:SetTextColor(1,1,1)
- ]]
- --[[ local netText = f:CreateFontString(nil,"OVERLAY")
- netText:SetPoint("TOPRIGHT",memText,"BOTTOMRIGHT",0,-3)
- f.netText = netText
- f.netText:SetFontObject("GameFontNormalSmall")
- f.netText:SetTextColor(1,1,1) ]]
- TinyMainbarInfo_OnLoad(f)
- end
- --[[
- text = GetCoinTextureString(money)
- tableitemids = GetInventoryItemsForSlot(slot)
- isdnd = UnitIsDND(unit)
- isafk = UnitIsAFK(unit)
- slot, texture = GetInventorySlotInfo(slotName)
- current, max = GetInventoryItemDurability(slot)
- isbroken = GetInventoryItemBroken(unit,slot)
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement