PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/databars/reputation.lua

http://github.com/Asphyxia/Tukui
Lua | 142 lines | 118 code | 23 blank | 1 comment | 17 complexity | 0b2ede86dbfde2960939dcf97d6c531c MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2
  3if C["databars"].reputation == true then
  4-- REPUTATION DATABARS
  5local RepData = {}
  6local db = C["databars"].reps
  7
  8local standing = {
  9	[-6000] = {255/255, 0,  51/255},      -- Hated :(
 10	[-3000] = {255/255, 0,  51/255},      -- Hostile
 11	[0] =     {255/255, 0,  51/255},      -- Unfriendly
 12	[3000] =  {255/255, 204/255, 102/255},-- Neutral
 13	[9000] =  {75/255,  175/255, 76/255}, -- Friendly
 14	[21000] = {75/255,  175/255, 76/255}, -- Honored
 15	[42000] = {75/255,  175/255, 76/255}, -- Revered
 16	[43000] = {75/255,  175/255, 76/255}, -- Exalted
 17}
 18
 19for i = 1, GetNumFactions() do
 20	local name, _, _, bottomValue, topValue, earnedValue, _, _, _, _, _, _, _ = GetFactionInfo(i)
 21	local min, max = earnedValue-bottomValue, topValue-bottomValue
 22
 23	if name == db[1] or name == db[2] or name == db[3] or name == db[4] or name == db[5] then
 24	
 25		local frame = CreateFrame("Frame", "RepData"..i, UIParent)
 26		frame:CreatePanel("Transparent", TukuiMinimap:GetWidth(), 18, "CENTER", UIParent, "CENTER", 0, 0)
 27		frame:EnableMouse(true)
 28		frame:Animate(160, 0, 0.4)
 29		frame:Hide()
 30		if T.Hydra then frame:SetBorder() end
 31		
 32		frame.Status = CreateFrame("StatusBar", "RepDataStatus"..i, frame)
 33		frame.Status:SetFrameLevel(12)
 34		frame.Status:SetStatusBarTexture(C["media"].normTex)
 35		frame.Status:SetMinMaxValues(0, max)
 36		frame.Status:SetValue(min)
 37		frame.Status:SetStatusBarColor(unpack(standing[topValue]))
 38		frame.Status:Point("TOPLEFT", frame, "TOPLEFT", 2, -2)
 39		frame.Status:Point("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2)
 40		
 41		frame.Text = frame.Status:CreateFontString(nil, "OVERLAY")
 42		frame.Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 43		frame.Text:Point("LEFT", frame, "LEFT", 6, 2)
 44		frame.Text:SetShadowColor(0, 0, 0)
 45		frame.Text:SetShadowOffset(1.25, -1.25)
 46		frame.Text:SetText(format("%s / %s", min, max))
 47		frame.Text:Hide()
 48		
 49		frame.Name = frame.Status:CreateFontString(nil, "OVERLAY")
 50		frame.Name:SetFont(C.media.pixelfont, C["datatext"].fontsize+1, "MONOCHROMEOUTLINE")
 51		frame.Name:Point("LEFT", frame, "LEFT", 6, 2)
 52		frame.Name:SetShadowColor(0, 0, 0)
 53		frame.Name:SetShadowOffset(1.25, -1.25)
 54		frame.Name:SetText(name)
 55		
 56		frame:SetScript("OnEnter", function(self)
 57			self.Name:Hide()
 58			self.Text:Show()
 59		end)
 60		
 61		frame:SetScript("OnLeave", function(self)
 62			self.Name:Show()
 63			self.Text:Hide()
 64		end)
 65		
 66		frame.id = i
 67		frame.Status = frame.Status
 68		frame.Text = frame.Text
 69		
 70		tinsert(RepData, frame)
 71	end
 72end
 73
 74for key, frame in ipairs(RepData) do
 75	frame:ClearAllPoints()
 76	if key == 1 then
 77		frame:Point("TOP", TukuiMinimap, "BOTTOM", 0, -3)
 78	else
 79		frame:Point("TOP", RepData[key-1], "BOTTOM", 0, -3)
 80	end
 81end
 82
 83local update = function()
 84	for _, frame in ipairs(RepData) do
 85		local name, _, _, bottomValue, topValue, earnedValue, _, _, _, _, _, _, _ = GetFactionInfo(frame.id)
 86		local min, max = earnedValue-bottomValue, topValue-bottomValue
 87		
 88		frame.Status:SetValue(min)
 89		frame.Text:SetText(format("%s / %s", min, max))
 90	end
 91end
 92
 93local function ModifiedBackdrop(self)
 94	local color = RAID_CLASS_COLORS[T.myclass]
 95	self:SetBackdropColor(color.r*.15, color.g*.15, color.b*.15)
 96	self:SetBackdropBorderColor(color.r, color.g, color.b)
 97end
 98
 99local function OriginalBackdrop(self)
100	self:SetTemplate("Default")
101end
102
103local toggle = CreateFrame("Frame", "RepToggle", TukuiChatBackgroundRight)
104toggle:CreatePanel(nil, 30, 15, "TOPRIGHT", TukuiChatBackgroundRight, "TOPRIGHT", -2, -52)
105toggle:EnableMouse(true)
106toggle:SetFrameStrata("MEDIUM")
107toggle:SetFrameLevel(10)
108toggle:CreateShadow("Default")
109toggle:CreateOverlay(toggle)
110toggle:SetAlpha(0)
111toggle:HookScript("OnEnter", ModifiedBackdrop)
112toggle:HookScript("OnLeave", OriginalBackdrop)
113
114toggle:SetScript("OnEnter", function()
115		if InCombatLockdown() then return end
116		toggle:FadeIn()
117	end)
118
119	toggle:SetScript("OnLeave", function()
120		toggle:FadeOut()
121	end)
122
123toggle.Text = toggle:CreateFontString(nil, "OVERLAY")
124toggle.Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
125toggle.Text:Point("CENTER", toggle, "CENTER", 1, 1)
126toggle.Text:SetText(T.datacolor.."R")
127
128toggle:SetScript("OnMouseUp", function(self)
129	for _, frame in pairs(RepData) do
130		if frame and frame:IsVisible() then
131			frame:SlideOut()
132		else
133			frame:SlideIn()
134		end
135	end
136end)
137
138local updater = CreateFrame("Frame")
139updater:RegisterEvent("PLAYER_ENTERING_WORLD")
140updater:RegisterEvent("UPDATE_FACTION")
141updater:SetScript("OnEvent", update)
142end