StatusReport.lua 12.2 KB
Newer Older
1
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
2
local LSM = E.Libs.LSM
3

Simpy's avatar
Simpy committed
4
local wipe, sort, unpack = wipe, sort, unpack
Simpy's avatar
Simpy committed
5
local next, pairs, tinsert = next, pairs, tinsert
Simpy's avatar
Simpy committed
6

7
local CreateFrame = CreateFrame
8 9 10 11 12 13 14
local GetAddOnInfo = GetAddOnInfo
local GetCVar = GetCVar
local GetLocale = GetLocale
local GetNumAddOns = GetNumAddOns
local GetRealZoneText = GetRealZoneText
local GetSpecialization = GetSpecialization
local GetSpecializationInfo = GetSpecializationInfo
Azilroka's avatar
Azilroka committed
15

16 17 18
function E:AreOtherAddOnsEnabled()
	local EP, addons, plugins = E.Libs.EP.plugins

19
	for i = 1, GetNumAddOns() do
Simpy's avatar
Simpy committed
20
		local name = GetAddOnInfo(i)
21 22
		if name ~= 'ElvUI' and name ~= 'ElvUI_OptionsUI' and E:IsAddOnEnabled(name) then
			if EP[name] then plugins = true else addons = true end
23 24
		end
	end
25 26

	return addons, plugins
27
end
28

29
function E:GetDisplayMode()
Simpy's avatar
Simpy committed
30 31
	local window, maximize = GetCVar('gxWindow') == '1', GetCVar('gxMaximize') == '1'
	return (window and maximize and 'Windowed (Fullscreen)') or (window and 'Windowed') or 'Fullscreen'
32 33 34
end

local EnglishClassName = {
Simpy's avatar
nothing  
Simpy committed
35 36 37 38 39 40 41 42 43 44 45 46
	DEATHKNIGHT = 'Death Knight',
	DEMONHUNTER = 'Demon Hunter',
	DRUID = 'Druid',
	HUNTER = 'Hunter',
	MAGE = 'Mage',
	MONK = 'Monk',
	PALADIN = 'Paladin',
	PRIEST = 'Priest',
	ROGUE = 'Rogue',
	SHAMAN = 'Shaman',
	WARLOCK = 'Warlock',
	WARRIOR = 'Warrior',
47 48 49
}

local EnglishSpecName = {
Simpy's avatar
Simpy committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
	[250] = 'Blood',
	[251] = 'Frost',
	[252] = 'Unholy',
	[102] = 'Balance',
	[103] = 'Feral',
	[104] = 'Guardian',
	[105] = 'Restoration',
	[253] = 'Beast Mastery',
	[254] = 'Marksmanship',
	[255] = 'Survival',
	[62] = 'Arcane',
	[63] = 'Fire',
	[64] = 'Frost',
	[268] = 'Brewmaster',
	[270] = 'Mistweaver',
	[269] = 'Windwalker',
	[65] = 'Holy',
	[66] = 'Protection',
	[70] = 'Retribution',
	[256] = 'Discipline',
	[257] = 'Holy',
	[258] = 'Shadow',
	[259] = 'Assasination',
	[260] = 'Combat',
	[261] = 'Sublety',
	[262] = 'Elemental',
	[263] = 'Enhancement',
	[264] = 'Restoration',
	[265] = 'Affliction',
	[266] = 'Demonoligy',
	[267] = 'Destruction',
	[71] = 'Arms',
	[72] = 'Fury',
	[73] = 'Protection',
	[577] = 'Havoc',
	[581] = 'Vengeance',
86 87 88 89 90 91
}

local function GetSpecName()
	return EnglishSpecName[GetSpecializationInfo(GetSpecialization())]
end

Simpy's avatar
take 2  
Simpy committed
92 93
function E:CreateStatusContent(num, width, parent, anchorTo, content)
	if not content then content = CreateFrame('Frame', nil, parent) end
Simpy's avatar
Simpy committed
94
	content:Size(width, (num * 20) + ((num-1)*5)) --20 height and 5 spacing
Simpy's avatar
Simpy committed
95
	content:Point('TOP', anchorTo, 'BOTTOM')
Simpy's avatar
Simpy committed
96

97
	local font = LSM:Fetch('font', 'Expressway')
98
	for i = 1, num do
Simpy's avatar
Simpy committed
99 100
		if not content['Line'..i] then
			local line = CreateFrame('Frame', nil, content)
Simpy's avatar
Simpy committed
101
			line:Size(width, 20)
Simpy's avatar
Simpy committed
102 103 104 105 106 107 108 109 110

			local text = line:CreateFontString(nil, 'ARTWORK')
			text:SetAllPoints()
			text:SetJustifyH('LEFT')
			text:SetJustifyV('MIDDLE')
			text:FontTemplate(font, 14, 'OUTLINE')
			line.Text = text

			if i == 1 then
Simpy's avatar
Simpy committed
111
				line:Point('TOP', content, 'TOP')
Simpy's avatar
Simpy committed
112
			else
Simpy's avatar
Simpy committed
113
				line:Point('TOP', content['Line'..(i-1)], 'BOTTOM', 0, -5)
Simpy's avatar
Simpy committed
114 115
			end

Simpy's avatar
Simpy committed
116
			content['Line'..i] = line
117 118 119 120 121 122 123 124 125 126 127 128 129
		end
	end

	return content
end

local function CloseClicked()
	if E.StatusReportToggled then
		E.StatusReportToggled = nil
		E:ToggleOptionsUI()
	end
end

Simpy's avatar
Simpy committed
130
function E:CreateStatusSection(width, height, headerWidth, headerHeight, parent, anchor1, anchorTo, anchor2, yOffset)
131 132
	local parentWidth, parentHeight = parent:GetSize()

Simpy's avatar
Simpy committed
133 134
	if width > parentWidth then parent:Width(width + 25) end
	if height then parent:Height(parentHeight + height) end
135 136

	local section = CreateFrame('Frame', nil, parent)
Simpy's avatar
Simpy committed
137
	section:Size(width, height or 0)
Simpy's avatar
Simpy committed
138
	section:Point(anchor1, anchorTo, anchor2, 0, yOffset)
139 140

	local header = CreateFrame('Frame', nil, section)
Simpy's avatar
Simpy committed
141
	header:Size(headerWidth or width, headerHeight)
Simpy's avatar
Simpy committed
142
	header:Point('TOP', section)
143 144
	section.Header = header

145
	local font = LSM:Fetch('font', 'Expressway')
Simpy's avatar
Simpy committed
146
	local text = section.Header:CreateFontString(nil, 'ARTWORK')
Simpy's avatar
Simpy committed
147 148
	text:Point('TOP')
	text:Point('BOTTOM')
149 150
	text:SetJustifyH('CENTER')
	text:SetJustifyV('MIDDLE')
Simpy's avatar
Simpy committed
151
	text:FontTemplate(font, 18, 'OUTLINE')
152 153 154
	section.Header.Text = text

	local leftDivider = section.Header:CreateTexture(nil, 'ARTWORK')
Simpy's avatar
Simpy committed
155
	leftDivider:Height(8)
Simpy's avatar
Simpy committed
156 157
	leftDivider:Point('LEFT', section.Header, 'LEFT', 5, 0)
	leftDivider:Point('RIGHT', section.Header.Text, 'LEFT', -5, 0)
Simpy's avatar
Simpy committed
158
	leftDivider:SetTexture([[Interface\Tooltips\UI-Tooltip-Border]])
159 160 161 162
	leftDivider:SetTexCoord(0.81, 0.94, 0.5, 1)
	section.Header.LeftDivider = leftDivider

	local rightDivider = section.Header:CreateTexture(nil, 'ARTWORK')
Simpy's avatar
Simpy committed
163
	rightDivider:Height(8)
Simpy's avatar
Simpy committed
164 165
	rightDivider:Point('RIGHT', section.Header, 'RIGHT', -5, 0)
	rightDivider:Point('LEFT', section.Header.Text, 'RIGHT', 5, 0)
Simpy's avatar
Simpy committed
166
	rightDivider:SetTexture([[Interface\Tooltips\UI-Tooltip-Border]])
167 168 169 170 171
	rightDivider:SetTexCoord(0.81, 0.94, 0.5, 1)
	section.Header.RightDivider = rightDivider

	return section
end
172

173
function E:CreateStatusFrame()
174
	--Main frame
Simpy's avatar
Simpy committed
175
	local StatusFrame = CreateFrame('Frame', 'ElvUIStatusReport', E.UIParent)
Simpy's avatar
Simpy committed
176
	StatusFrame:Point('CENTER', E.UIParent, 'CENTER')
Simpy's avatar
Simpy committed
177 178
	StatusFrame:SetFrameStrata('HIGH')
	StatusFrame:CreateBackdrop('Transparent', nil, true)
179 180
	StatusFrame.backdrop:SetBackdropColor(0, 0, 0, 0.6)
	StatusFrame:SetMovable(true)
Simpy's avatar
Simpy committed
181
	StatusFrame:Size(0, 35)
Simpy's avatar
Simpy committed
182
	StatusFrame:Hide()
183

Simpy's avatar
Simpy committed
184 185
	--Plugin frame
	local PluginFrame = CreateFrame('Frame', 'ElvUIStatusPlugins', StatusFrame)
Simpy's avatar
Simpy committed
186
	PluginFrame:Point('TOPLEFT', StatusFrame, 'TOPRIGHT', E.Border * 2, 0)
Simpy's avatar
Simpy committed
187 188
	PluginFrame:SetFrameStrata('HIGH')
	PluginFrame:CreateBackdrop('Transparent', nil, true)
Simpy's avatar
Simpy committed
189
	PluginFrame.backdrop:SetBackdropColor(0, 0, 0, 0.6)
Simpy's avatar
Simpy committed
190
	PluginFrame:Size(0, 25)
Simpy's avatar
Simpy committed
191 192
	StatusFrame.PluginFrame = PluginFrame

Simpy's avatar
Simpy committed
193 194
	--Close button and script to retoggle the options.
	StatusFrame:CreateCloseButton()
195 196
	StatusFrame.CloseButton:HookScript('OnClick', CloseClicked)

197
	--Title logo (drag to move frame)
Simpy's avatar
Simpy committed
198
	local titleLogoFrame = CreateFrame('Frame', nil, StatusFrame, 'TitleDragAreaTemplate')
Simpy's avatar
Simpy committed
199
	titleLogoFrame:Point('CENTER', StatusFrame, 'TOP')
Simpy's avatar
Simpy committed
200
	titleLogoFrame:Size(240, 80)
Simpy's avatar
Simpy committed
201 202
	StatusFrame.TitleLogoFrame = titleLogoFrame

203
	local LogoTop = StatusFrame.TitleLogoFrame:CreateTexture(nil, 'ARTWORK')
Simpy's avatar
Simpy committed
204
	LogoTop:Point('CENTER', titleLogoFrame, 'TOP', 0, -36)
205
	LogoTop:SetTexture(E.Media.Textures.LogoTopSmall)
Simpy's avatar
Simpy committed
206
	LogoTop:Size(128, 64)
207 208 209
	titleLogoFrame.LogoTop = LogoTop

	local LogoBottom = StatusFrame.TitleLogoFrame:CreateTexture(nil, 'ARTWORK')
Simpy's avatar
Simpy committed
210
	LogoBottom:Point('CENTER', titleLogoFrame, 'TOP', 0, -36)
211
	LogoBottom:SetTexture(E.Media.Textures.LogoBottomSmall)
Simpy's avatar
Simpy committed
212
	LogoBottom:Size(128, 64)
213
	titleLogoFrame.LogoBottom = LogoBottom
214 215

	--Sections
Simpy's avatar
Simpy committed
216 217 218 219
	StatusFrame.Section1 = E:CreateStatusSection(300, 125, nil, 30, StatusFrame, 'TOP', StatusFrame, 'TOP', -30)
	StatusFrame.Section2 = E:CreateStatusSection(300, 150, nil, 30, StatusFrame, 'TOP', StatusFrame.Section1, 'BOTTOM', 0)
	StatusFrame.Section3 = E:CreateStatusSection(300, 185, nil, 30, StatusFrame, 'TOP', StatusFrame.Section2, 'BOTTOM', 0)
	--StatusFrame.Section4 = E:CreateStatusSection(300, 60, nil, 30, StatusFrame, 'TOP', StatusFrame.Section3, 'BOTTOM', 0)
Simpy's avatar
take 2  
Simpy committed
220
	PluginFrame.SectionP = E:CreateStatusSection(280, nil, nil, 30, PluginFrame, 'TOP', PluginFrame, 'TOP', -10)
221

222
	--Section content
Simpy's avatar
Simpy committed
223 224 225
	StatusFrame.Section1.Content = E:CreateStatusContent(4, 260, StatusFrame.Section1, StatusFrame.Section1.Header)
	StatusFrame.Section2.Content = E:CreateStatusContent(5, 260, StatusFrame.Section2, StatusFrame.Section2.Header)
	StatusFrame.Section3.Content = E:CreateStatusContent(6, 260, StatusFrame.Section3, StatusFrame.Section3.Header)
226
	--StatusFrame.Section4.Content = CreateFrame('Frame', nil, StatusFrame.Section4)
Simpy's avatar
Simpy committed
227
	--StatusFrame.Section4.Content:Size(240, 25)
Simpy's avatar
Simpy committed
228
	--StatusFrame.Section4.Content:Point('TOP', StatusFrame.Section4.Header, 'BOTTOM', 0, 0)
229 230

	--Content lines
Simpy's avatar
Simpy committed
231
	StatusFrame.Section1.Content.Line3.Text:SetFormattedText('Recommended Scale: |cff4beb2c%s|r', E:PixelBestSize())
Simpy's avatar
Simpy committed
232 233 234 235 236 237 238
	StatusFrame.Section1.Content.Line4.Text:SetFormattedText('UI Scale Is: |cff4beb2c%s|r', E.global.general.UIScale)
	StatusFrame.Section2.Content.Line1.Text:SetFormattedText('Version of WoW: |cff4beb2c%s (build %s)|r', E.wowpatch, E.wowbuild)
	StatusFrame.Section2.Content.Line2.Text:SetFormattedText('Client Language: |cff4beb2c%s|r', GetLocale())
	StatusFrame.Section2.Content.Line5.Text:SetFormattedText('Using Mac Client: |cff4beb2c%s|r', (E.isMacClient == true and 'Yes' or 'No'))
	StatusFrame.Section3.Content.Line1.Text:SetFormattedText('Faction: |cff4beb2c%s|r', E.myfaction)
	StatusFrame.Section3.Content.Line2.Text:SetFormattedText('Race: |cff4beb2c%s|r', E.myrace)
	StatusFrame.Section3.Content.Line3.Text:SetFormattedText('Class: |cff4beb2c%s|r', EnglishClassName[E.myclass])
239

240
	--[[Export buttons
Simpy's avatar
Simpy committed
241
	StatusFrame.Section4.Content.Button1 = CreateFrame('Button', nil, StatusFrame.Section4.Content, 'UIPanelButtonTemplate')
Simpy's avatar
Simpy committed
242
	StatusFrame.Section4.Content.Button1:Size(100, 25)
Simpy's avatar
Simpy committed
243
	StatusFrame.Section4.Content.Button1:Point('LEFT', StatusFrame.Section4.Content, 'LEFT')
Simpy's avatar
Simpy committed
244 245 246
	StatusFrame.Section4.Content.Button1:SetText('Forum')
	StatusFrame.Section4.Content.Button1:SetButtonState('DISABLED')
	StatusFrame.Section4.Content.Button2 = CreateFrame('Button', nil, StatusFrame.Section4.Content, 'UIPanelButtonTemplate')
Simpy's avatar
Simpy committed
247
	StatusFrame.Section4.Content.Button2:Size(100, 25)
Simpy's avatar
Simpy committed
248
	StatusFrame.Section4.Content.Button2:Point('RIGHT', StatusFrame.Section4.Content, 'RIGHT')
Simpy's avatar
Simpy committed
249 250
	StatusFrame.Section4.Content.Button2:SetText('Ticket')
	StatusFrame.Section4.Content.Button2:SetButtonState('DISABLED')
Simpy's avatar
Simpy committed
251
	Skins:HandleButton(StatusFrame.Section4.Content.Button1, true)
252
	Skins:HandleButton(StatusFrame.Section4.Content.Button2, true)]]
253

Simpy's avatar
Simpy committed
254
	return StatusFrame
255 256
end

Simpy's avatar
Simpy committed
257 258
local function pluginSort(a, b)
	local A, B = a.title or a.name, b.title or b.name
Simpy's avatar
Simpy committed
259 260 261
	if A and B then
		return E:StripString(A) < E:StripString(B)
	end
Simpy's avatar
Simpy committed
262 263
end

Simpy's avatar
take 2  
Simpy committed
264
local pluginData = {}
265
function E:UpdateStatusFrame()
Simpy's avatar
Simpy committed
266
	local StatusFrame = E.StatusFrame
Simpy's avatar
Simpy committed
267
	local PluginFrame = StatusFrame.PluginFrame
Simpy's avatar
Simpy committed
268

269 270 271 272 273
	--Section headers
	local valueColor = E.media.hexvaluecolor
	StatusFrame.Section1.Header.Text:SetFormattedText('%sAddOn Info|r', valueColor)
	StatusFrame.Section2.Header.Text:SetFormattedText('%sWoW Info|r', valueColor)
	StatusFrame.Section3.Header.Text:SetFormattedText('%sCharacter Info|r', valueColor)
274
	--StatusFrame.Section4.Header.Text:SetFormattedText('%sExport To|r', valueColor)
Simpy's avatar
take 2  
Simpy committed
275 276 277

	local PluginSection = PluginFrame.SectionP
	PluginSection.Header.Text:SetFormattedText('%sPlugins|r', valueColor)
278 279 280 281 282 283 284

	local verWarning = E.recievedOutOfDateMessage and 'ff3333' or E.shownUpdatedWhileRunningPopup and 'ff9933'
	StatusFrame.Section1.Content.Line1.Text:SetFormattedText('Version of ElvUI: |cff%s%s|r', verWarning or '33ff33', E.version)

	local addons, plugins = E:AreOtherAddOnsEnabled()
	StatusFrame.Section1.Content.Line2.Text:SetFormattedText('Other AddOns Enabled: |cff%s|r', (not addons and plugins and 'ff9933Plugins') or (addons and 'ff3333Yes') or '33ff33No')

Simpy's avatar
Simpy committed
285
	if plugins then
Simpy's avatar
Simpy committed
286
		wipe(pluginData)
Simpy's avatar
Simpy committed
287
		for _, data in pairs(E.Libs.EP.plugins) do
Simpy's avatar
Simpy committed
288 289 290
			if data and not data.isLib then
				tinsert(pluginData, data)
			end
Simpy's avatar
take 2  
Simpy committed
291 292
		end

Simpy's avatar
Simpy committed
293
		if next(pluginData) then
Simpy's avatar
Simpy committed
294 295
			sort(pluginData, pluginSort)

Simpy's avatar
Simpy committed
296
			local count = #pluginData
Simpy's avatar
Simpy committed
297
			local width = PluginSection:GetWidth()
Simpy's avatar
Simpy committed
298
			PluginSection.Content = E:CreateStatusContent(count, width, PluginSection, PluginSection.Header, PluginSection.Content)
Simpy's avatar
Simpy committed
299

Simpy's avatar
Simpy committed
300 301
			for i=1, count do
				local data = pluginData[i]
Simpy's avatar
Simpy committed
302
				local color = data.old and 'ff3333' or '33ff33'
Simpy's avatar
grey v  
Simpy committed
303
				PluginSection.Content['Line'..i].Text:SetFormattedText('%s |cff888888v|r|cff%s%s|r', data.title or data.name, color, data.version)
Simpy's avatar
Simpy committed
304 305
			end

Simpy's avatar
Simpy committed
306
			PluginFrame.SectionP:Height(count * 20)
Simpy's avatar
Simpy committed
307
			PluginFrame:Height(PluginSection.Content:GetHeight() + 50)
Simpy's avatar
Simpy committed
308
			PluginFrame:Show()
Simpy's avatar
Simpy committed
309 310
		else
			PluginFrame:Hide()
Simpy's avatar
Simpy committed
311
		end
Simpy's avatar
Simpy committed
312 313 314 315
	else
		PluginFrame:Hide()
	end

Simpy's avatar
Simpy committed
316
	local Section2 = StatusFrame.Section2
317
	Section2.Content.Line3.Text:SetFormattedText('Display Mode: |cff4beb2c%s|r', E:GetDisplayMode())
Simpy's avatar
Simpy committed
318 319 320 321 322
	Section2.Content.Line4.Text:SetFormattedText('Resolution: |cff4beb2c%s|r', E.resolution)

	local Section3 = StatusFrame.Section3
	Section3.Content.Line4.Text:SetFormattedText('Specialization: |cff4beb2c%s|r', GetSpecName())
	Section3.Content.Line5.Text:SetFormattedText('Level: |cff4beb2c%s|r', E.mylevel)
323
	Section3.Content.Line6.Text:SetFormattedText('Zone: |cff4beb2c%s|r', GetRealZoneText() or UNKNOWN)
324 325

	StatusFrame.TitleLogoFrame.LogoTop:SetVertexColor(unpack(E.media.rgbvaluecolor))
326 327
end

328
function E:ShowStatusReport()
Simpy's avatar
Simpy committed
329 330
	if not E.StatusFrame then
		E.StatusFrame = E:CreateStatusFrame()
331 332
	end

Simpy's avatar
Simpy committed
333
	if not E.StatusFrame:IsShown() then
334
		E:UpdateStatusFrame()
Simpy's avatar
Simpy committed
335 336
		E.StatusFrame:Raise() --Set framelevel above everything else
		E.StatusFrame:Show()
337
	else
Simpy's avatar
Simpy committed
338
		E.StatusFrame:Hide()
339
	end
Simpy's avatar
Simpy committed
340
end