WoWInterface SVN fernir_UI

[/] [core.lua] - Rev 2

Compare with Previous | Blame | View Log

fernir_UI = CreateFrame("Frame", nil, UIParent)
fernir_UI:Show()

--[[     Options start here     ]]
local _G = getfenv(0)
local guildtable = {}
local objects = {}
local get_guild = "# / #"
local tcolor = "637eae"
local settings = oUF_Settings
local objCount = 12
local damage, ctime, stime = 0, 0, 0

--[[        Options end         ]]


SlashCmdList.RELOADUI = ReloadUI
SLASH_RELOADUI1 = "/rl"
SLASH_RELOADUI2 = "/кд"

SlashCmdList.RCSLASH = DoReadyCheck
SLASH_RCSLASH1 = "/rc"
SLASH_RCSLASH2 = "/кс"


util = {

    round = function(val, num) return (floor(val*10*num))/(10*num) end, 
    rgbt2str = function(col) local r, g, b = unpack(col) return format("|cff%02x%02x%02x", r*255, g*255, b*255) end, 
    rgb2str = function(r, g, b) return format("|cff%02x%02x%02x", r*255, g*255, b*255) end, 
    money = function(val) return format("|cffffd700%d|r.|cffbbbbdd%d|r.|cffeda55f%d|r", mod(val/10000, 10000), mod(val/100, 100), mod(val, 100)) end, 
   
    level = function(val)
        local lcol = GetDifficultyColor(val) 
        if not lcol then return 1, 1, 1 end
        return lcol.r, lcol.g, lcol.b
    end, 

    letter = function(value)
        if value then
           if value < 1 then
              return string.format("%.2f", value)
           elseif value >= 10000000 then 
              return string.format("%.1fm", value / 1000000) 
           elseif value >= 1000000 then
              return string.format("%.2fm", value / 1000000) 
           elseif value >= 100000 then
              return string.format("%.0fk", value / 1000) 
           elseif value >= 10000 then
              return string.format("%.1fk", value / 1000) 
           else
              return math.ceil(value)
           end
        end
    end, 

    gradient_s = function(val, bad, good)
        gradient = function(val, bad, good)
            local percent, r, g
            if (good > bad) then 
                percent = val/(good-bad)
            else 
                percent = 1-val/(bad-good) 
            end
            if (percent > 1) then percent = 1 end
            if (percent < 0) then percent = 0 end
            if(percent < 0.5) then r, g = 1, 2*percent   else  r, g = (1-percent)*2, 1 end
            return r, g, 0
        end
        return util.rgb2str(gradient(val, bad, good))..val.."|r"
    end, 
   
}

local line  = function(m1, m2) GameTooltip:AddDoubleLine(m1, m2, 0.5, 02, 0.7, 0.7, 0.7, 0.2) end
local space = function() GameTooltip:AddLine("\n") end

local aFrame = CreateFrame("Frame", "fernir_UI_Window", MinimapCanvas)

local createFs = function(parent, justify, ownfsize)
    local f = parent:CreateFontString(nil, "OVERLAY")
    f:SetFont(settings.font, ownfsize or settings.fsize, "THINOUTLINE")
    if(justify) then f:SetJustifyH(justify) end
    return f
end
    
fernir_UI.PLAYER_LOGIN = function(self, ...)
    if (settings.UIScale) then
        local index = GetCurrentResolution()
        local resolution = select(index, GetScreenResolutions())
        if(resolution == "1680x1050" or resolution == "1920x1080" or resolution == "1920x1200" or resolution == "1600x900" or resolution == "1440x900") then
            SetCVar("useUiScale", 1)
            SetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))
        else
            print("Current resolution:", resolution)
            SetCVar("useUiScale", 0)
            StaticPopup_Show("DISABLE_UI")
        end
    end
end

fernir_UI.ADDON_LOADED = function(self, ...)
    
    if arg1 ~= "fernir_UI" then 
        return 
    end

    --[[ Changing some variables ]]
    
    SetCVar("screenshotQuality", 10)
    SetCVar("cameraDistanceMax", 50)
    SetCVar("cameraDistanceMaxFactor", 3.4)
    
    aFrame:SetFrameStrata("BACKGROUND")
    local tt = aFrame:CreateTexture(nil, "BACKGROUND")
    tt:SetTexture(settings.texture)
    tt:SetVertexColor(.2, .2, .2, .4)
    tt:SetAllPoints(aFrame)
    aFrame:SetPoint("TOPLEFT", UIParent)
    aFrame:SetPoint("TOPRIGHT", UIParent)
    aFrame:SetHeight(15)
    aFrame:Show()
    
    cString("gold")
    cString("dura", "progress", 0, 100)
    cString("lag")
    cString("guild", show_guild)
    cString("loot")
    cString("xp", "progress", 0, 100)
    cString("mem", show_addons)
    cString("wgtime")
    cString("honor")
    cString("fps", "progress", 0, 200)
    cString("dps")
    cString("zone")
    
    checkStats()
    
    for i, object in pairs(objects) do
        object.bar:SetWidth(object.text:GetStringWidth()+30)
    end
    
    --GuildRoster()
    fernir_UI.GUILD_ROSTER_UPDATE()
    
    updFrame = CreateFrame("Frame")
    updFrame.timeSinceLastUpdate = 0
    updFrame:SetScript("OnUpdate", function(this, elapsed)  
        updFrame.timeSinceLastUpdate = updFrame.timeSinceLastUpdate + elapsed
        
        if (updFrame.timeSinceLastUpdate >= 1) then
            checkStats()
            updFrame.timeSinceLastUpdate = 0
        end
    end)
end

function checkStats()
    for i, object in pairs(objects) do
        if (i=="gold") then
            object.text:SetText("|TInterface\\BUTTONS\\UI-GroupLoot-Coin-Up:0:0:0:-1|t "..util.money(GetMoney()))
        elseif i=="dura" then
            object.text:SetText("|TInterface\\MINIMAP\\Tracking\\Repair:0:0:0:-1|t "..select(1, show_durability()).."  ")
            object.progress:SetValue(select(2, show_durability()) or 0)
        elseif i=="fps" then
            object.text:SetText(" |cff"..tcolor.." fps:|r "..floor(GetFramerate()))
            object.progress:SetValue(floor(GetFramerate()))
        elseif i=="tm" then
            object.text:SetText("|cff"..tcolor.." T: |r"..date("%H:%M").."  ")
        elseif i=="lag" then
            object.text:SetText("|TInterface\\MINIMAP\\Tracking\\FlightMaster:0:0:0:-1|t "..select(3, GetNetStats()))
        elseif i=="loot" then
            if UnitInParty("player") or UnitInRaid("player") then
                object.text:SetText("|TInterface\\MINIMAP\\Tracking\\Banker:0:0:0:-1|t "..show_loot())
            end
        elseif i=="xp" then
            if UnitLevel("player") < 80 then
                object.text:SetText("|cff"..tcolor.." XP:|r |caa0033ee"..util.letter((UnitXPMax("player")-UnitXP("player")) + 1).." ("..util.letter(GetXPExhaustion() or 0)..")|r") 
                object.progress:SetValue((floor((UnitXP("player")/UnitXPMax("player"))*100)))
            else
                object.progress = nil
            end
        elseif i=="guild" then
            if IsInGuild() then
                object.text:SetText("|TInterface\\MINIMAP\\Tracking\\Profession:0:0:0:-1|t "..get_guild)
            end
        elseif i=="mem" then
            object.text:SetText("|cff"..tcolor.." M:|r "..memoryval(collectgarbage("count")))
        elseif i=="wgtime" then
            object.text:SetText("|TInterface\\PVPFrame\\PVP-Currency-Alliance:0:0:0:-1|t "..WGConvertTime(GetWintergraspWaitTime()))
        elseif i=="honor" then
            object.text:SetText("|TInterface\\MINIMAP\\Tracking\\BattleMaster:0:0:0:-1|t "..util.letter(GetHonorCurrency()))
        elseif i=="zone" then
            object.text:SetText(GetMinimapZoneText())
        elseif i=="dps" then
        else
        end
    end
end

function WGConvertTime(value)
        if(value~=nil)then
                local hours = floor(value / 3600)
                local minutes = value - (hours * 3600)
                minutescorrupt = floor(minutes / 60)
                if(minutescorrupt < 10)then minutesfixed = "0"..minutescorrupt..""
                else minutesfixed = minutescorrupt end
                local seconds = floor(value - ((hours * 3600) + (minutescorrupt * 60)))
                if(seconds < 10)then secondsfixed = "0"..seconds..""
                else secondsfixed = seconds end
                if (hours > 0) then
                        return hours..":"..minutesfixed..":"..secondsfixed
                elseif (minutescorrupt > 0) then
                        return "0:"..minutesfixed..":"..secondsfixed
                else
                        return "0:00:"..secondsfixed
                end
        end
   return ""
end

function show_addons()
   GameTooltip:SetOwner(aFrame, "ANCHOR_BOTTOMRIGHT")
   local total, addons, all_mem = 0, {}, collectgarbage("count")
    UpdateAddOnMemoryUsage()  
    for i=1, GetNumAddOns(), 1 do  
      if (GetAddOnMemoryUsage(i) > 0 ) then
        memory = GetAddOnMemoryUsage(i)  
        entry = {name=GetAddOnInfo(i), memory = memory}  
        table.insert(addons, entry)  
        total = total + memory  
      end
    end  
    table.sort(addons, function(a, b) return a.memory > b.memory end)  
    line("ADDONS MEMORY USAGE :", "\n")  
   i = 0  
    for _, entry in pairs(addons) do  
        line(entry.name, memoryval(entry.memory)) 
        i = i + 1  
        if i >= 50 then  break  end  
    end  
    space()
    line("Addons", memoryval(total))
    line("Blizz", memoryval(all_mem-total))
    line("Total", memoryval(all_mem))
    if not UnitAffectingCombat("player") then GameTooltip:Show() end
end

function cString(name, point, ...)
    
    local lastobject = nil
    for i, object in pairs(objects) do
        if object.child == false then
            objects[i].child = true
            lastobject = objects[i]
            break
        end
    end

    local btn = CreateFrame("Frame", nil, aFrame)
        
    if (lastobject) then
        btn:SetPoint("LEFT", lastobject.bar, "RIGHT", 0, 0)
    else
        btn:SetPoint("LEFT", aFrame, "LEFT", 0, 0)
    end
    
    btn:SetWidth(UIParent:GetWidth()/objCount)
    btn:SetHeight(aFrame:GetHeight())
    btn:EnableMouse(true)
    btn:Show()

        
    if type(point) == "string" then
        if point == "progress" then
            local val1, val2 = select(1, ...)
            btn.pb = CreateFrame("StatusBar", nil, btn)
            btn.pb:SetStatusBarTexture(settings.striped)
            btn.pb:SetStatusBarColor(.15, .15, .15)
            btn.pb.frequentUpdates = true
            btn.pb:SetPoint("TOPLEFT", btn, "TOPLEFT", 1, -1)
            btn.pb:SetPoint("BOTTOMRIGHT", btn, "BOTTOMRIGHT", -1, 1)
            btn.pb:SetMinMaxValues(val1, val2)
            
            local ppbg = btn.pb:CreateTexture(nil, "BACKGROUND")
            ppbg:SetTexture(settings.texture)
            ppbg:SetAllPoints(btn.pb)
            ppbg:SetVertexColor(.3, .3, .3)
            
            local zstr = createFs(btn.pb, nil, 10)
            zstr:SetAllPoints(btn.pb)
            
            objects[name] = {
                ["text"] = zstr, 
                ["bar"] = btn, 
                ["progress"] = btn.pb, 
                ["child"] = false, 
            }
        end
    elseif type(point) == "function" then
        btn:SetScript("OnEnter", point)
        btn:SetScript("OnLeave", function() GameTooltip:Hide() end)

        local zstr = btn:CreateFontString(nil, "OVERLAY")
        zstr:SetFont(settings.font, 10, "THINOUTLINE")
        zstr:SetAllPoints(btn)
        zstr:SetTextColor(0, 1, 0.2, 1)
        zstr:SetJustifyV("MIDDLE")
    
        objects[name] = {
            ["text"] = zstr, 
            ["bar"] = btn, 
            ["progress"] = nil, 
            ["child"] = false, 
        }
        
    else
        local zstr = btn:CreateFontString(nil, "OVERLAY")
        zstr:SetFont(settings.font, 10, "THINOUTLINE")
        zstr:SetAllPoints(btn)
        zstr:SetTextColor(0, 1, 0.2, 1)
        zstr:SetJustifyV("MIDDLE")
    
        objects[name] = {
            ["text"] = zstr, 
            ["bar"] = btn, 
            ["progress"] = nil, 
            ["child"] = false, 
        }
    end    

    return btn
end

function show_durability()
   local cost, ndx, durability, d_val, d_max = GetRepairAllCost(), 0, 0, 0, 0
   for slot = 0, 19 do
      d_val, d_max = GetInventoryItemDurability(slot)
      if(d_val) then durability = durability + d_val/d_max*100 ndx=ndx+1 
      end 
   end
   durability = floor(durability/ndx)
   local out_string = util.gradient_s(floor(durability), 0, 100).." % "
   if(cost > 0) then return out_string.."["..cost.."]" end
   return out_string, durability+1
end

function show_guild()
   GameTooltip:SetOwner(aFrame, "ANCHOR_BOTTOMRIGHT")  
   line("guild :", GetGuildInfo("player"))
   space()
   for _, val in ipairs(guildtable) do
        line(string.format("|cffdddd00%s|r  %s|r  [ %s ]", val[1], classcol(val[9])..val[2], val[4], val[5]), val[5])
   end
   if not UnitAffectingCombat("player") then GameTooltip:Show() end
end

function memoryval(val)
   if val > 1024 then return floor(val/1024).." mb"
   else return floor(val).." kb" end
end

fernir_UI.GUILD_ROSTER_UPDATE = function(self, ...)
   local total, online = 0, 0
   guildtable = {}
   if IsInGuild() then
      total = GetNumGuildMembers(true)
      for ndx = 0, total do
         name, rnk, irnk, lvl, class, zone, note, onote, on, status, engclass = GetGuildRosterInfo(ndx)
         if(on and name) then 
            online = online + on 
            table.insert(guildtable, {lvl, name, class, zone, note, onote, on, status, engclass})
          end
     end
   end
   get_guild = online.."/"..total
end

function show_loot()
    local lootmethod, masterlooterPartyID, masterlooterRaidID = GetLootMethod()
    local master = ""
    if masterlooterPartyID then 
        master = ", "..UnitName("party"..masterlooterPartyID)
    elseif masterlooterRaidID then
        master = ", "..UnitName("raid"..masterlooterPartyID)
    else
        master = ""
    end
    
    objects["loot"].bar:SetWidth(objects["loot"].text:GetStringWidth()+30)
    return format("%s %s", lootmethod, master)
end

function classcol(class)
   if not _G["RAID_CLASS_COLORS"]  then return ("|cffffffff") end
   local color = _G["RAID_CLASS_COLORS"][strupper(class)]
   return format("|cff%02x%02x%02x", color.r*255, color.g*255, color.b*255)
end



fernir_UI.PLAYER_ENTERING_WORLD = function(self, ...)
    fernir_UI:UnregisterEvent("PLAYER_ENTERING_WORLD" )
    
    --WatchFrame:ClearAllPoints()
    --WatchFrame:SetPoint("TOPLEFT", "UIParent", "TOPRIGHT", -350, -300)
    --WatchFrame:SetHeight(600)
    --WatchFrame.ClearAllPoints = function() end
    --WatchFrame.SetPoint = function() end
    --WatchFrame.SetAllPoints = function() end 

    local color = _G["RAID_CLASS_COLORS"][select(2, UnitClass("player"))] or {0,0,0}
    tcolor = format("%02x%02x%02x", color.r*255, color.g*255, color.b*255) --"637eae"
end

fernir_UI.PLAYER_REGEN_ENABLED = function(self, ...)
    damage = 0
    stime = 0
    ctime = 0
    self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end

fernir_UI.PLAYER_REGEN_DISABLED = function(self, ...)
    stime = GetTime()    
    self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end

fernir_UI.COMBAT_LOG_EVENT_UNFILTERED = function(_, _, timestamp, event, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, meleedamage, _, _, spelldamage)
    if sourceGUID == UnitGUID("player") or  sourceGUID == UnitGUID("playerpet") then      
        local duration = 1
        if ( event == "SWING_DAMAGE" ) then
            damage = damage + meleedamage
            ctime = GetTime()
            if ((ctime - stime) > 1) then
                duration = ctime - stime
            end
            objects["dps"].text:SetText(" |cff"..tcolor.." DPS:|r "..floor(damage / duration))
            objects["dps"].bar:SetWidth(objects["dps"].text:GetStringWidth() + 30)
        elseif (event == "SPELL_DAMAGE" or event == "SPELL_PERIODIC_DAMAGE") then
            damage = damage + spelldamage
            
            ctime = GetTime()
            if ((ctime - stime) > 1) then
                duration = ctime - stime
            end
            objects["dps"].text:SetText(" |cff"..tcolor.." DPS:|r "..floor(damage / duration))
            objects["dps"].bar:SetWidth(objects["dps"].text:GetStringWidth() + 30)
        end
        end
end


    WatchFrame:SetFrameStrata("TOOLTIP")
    WatchFrame:ClearAllPoints()
    --WatchFrame:SetPoint("TOPLEFT", UIParent, "TOPRIGHT", 350,-300)
    WatchFrame:SetHeight(600)
    WatchFrame.ClearAllPoints = function() end
    WatchFrame.SetPoint = function() end
    WatchFrame.SetAllPoints = function() end
    WatchFrame:SetMovable(true)
    WatchFrameCollapseExpandButton:RegisterForDrag("LeftButton")
    WatchFrame:SetUserPlaced(true)
    WatchFrameCollapseExpandButton:HookScript('OnDragStart', function(self) WatchFrame:StartMoving() end)
    WatchFrameCollapseExpandButton:HookScript('OnDragStop', function(self) WatchFrame:StopMovingOrSizing() end)
    WatchFrameCollapseExpandButton.Hide = function() end
    
fernir_UI:RegisterEvent("ADDON_LOADED")
fernir_UI:RegisterEvent("PLAYER_ENTERING_WORLD")
fernir_UI:RegisterEvent("GUILD_ROSTER_UPDATE")
fernir_UI:RegisterEvent("PLAYER_LOGIN")
fernir_UI:RegisterEvent("PLAYER_REGEN_DISABLED")
fernir_UI:RegisterEvent("PLAYER_REGEN_ENABLED")

fernir_UI:SetScript("OnEvent", function(self, event, ...) self[event](self, event, ...) end) 

Compare with Previous | Blame