| yellowfive@57 | 1 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot") | 
| yellowfive@57 | 2 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true) | 
| yellowfive@57 | 3 local AceGUI = LibStub("AceGUI-3.0") | 
| yellowfive@57 | 4 | 
| yellowfive@57 | 5 -- used to make some stuff layer correctly | 
| yellowfive@57 | 6 Amr.FrameLevels = { | 
| yellowfive@57 | 7 	High = 100, | 
| yellowfive@57 | 8 	Highest = 125 | 
| yellowfive@57 | 9 } | 
| yellowfive@57 | 10 | 
| yellowfive@57 | 11 -- standard colors used throughout the UI (in standard 0-255 RGB format, game uses 0-1 decimals, but we auto-convert it below) | 
| yellowfive@57 | 12 Amr.Colors = { | 
| yellowfive@57 | 13 	White =              { R = 255, G = 255, B = 255 }, | 
| yellowfive@57 | 14 	Black =              { R =   0, G =   0, B =   0 }, | 
| yellowfive@57 | 15 	Gray =               { R = 153, G = 153, B = 153 }, | 
| yellowfive@57 | 16 	Orange =             { R = 201, G =  87, B =   1 }, | 
| yellowfive@57 | 17 	Green =              { R =  77, G = 134, B =  45 }, | 
| yellowfive@57 | 18 	Blue =               { R =  54, G = 172, B = 204 }, | 
| yellowfive@57 | 19 	Red =                { R = 204, G =  38, B =  38 }, | 
| yellowfive@57 | 20 	Gold =               { R = 255, G = 215, B =   0 }, | 
| yellowfive@57 | 21 	BrightGreen =        { R =   0, G = 255, B =   0 }, | 
| yellowfive@57 | 22 	Text =               { R = 255, G = 255, B = 255 }, | 
| yellowfive@57 | 23 	TextHover =          { R = 255, G = 255, B =   0 }, | 
| yellowfive@57 | 24 	TextGray =           { R = 120, G = 120, B = 120 }, | 
| yellowfive@57 | 25 	TextHeaderActive =   { R = 223, G = 134, B =  61 }, | 
| yellowfive@57 | 26 	TextHeaderDisabled = { R = 188, G = 188, B = 188 }, | 
| yellowfive@57 | 27 	TextTan =            { R = 223, G = 192, B = 159 }, | 
| yellowfive@57 | 28 	BorderBlue =         { R =  26, G =  83, B =  98 }, | 
| yellowfive@57 | 29 	BorderGray =         { R =  96, G =  96, B =  96 }, | 
| yellowfive@57 | 30 	Bg =                 { R =  41, G =  41, B =  41 }, | 
| yellowfive@57 | 31 	BgInput =            { R =  17, G =  17, B =  17 }, | 
| yellowfive@57 | 32 	BarHigh =            { R = 114, G = 197, B =  66 }, | 
| yellowfive@57 | 33 	BarMed =             { R = 255, G = 196, B =  36 }, | 
| yellowfive@57 | 34 	BarLow =             { R = 201, G =  87, B =   1 } | 
| yellowfive@57 | 35 } | 
| yellowfive@57 | 36 | 
| yellowfive@57 | 37 -- convert from common RGB to 0-1 RGB values | 
| yellowfive@57 | 38 for k,v in pairs(Amr.Colors) do | 
| yellowfive@57 | 39 	v.R = v.R / 255 | 
| yellowfive@57 | 40 	v.G = v.G / 255 | 
| yellowfive@57 | 41 	v.B = v.B / 255 | 
| yellowfive@57 | 42 end | 
| yellowfive@57 | 43 | 
| yellowfive@57 | 44 -- get colors for classes from WoW's constants | 
| yellowfive@57 | 45 Amr.Colors.Classes = {} | 
| yellowfive@57 | 46 for k,v in pairs(RAID_CLASS_COLORS) do | 
| yellowfive@57 | 47 	Amr.Colors.Classes[k] = { R = v.r, G = v.g, B = v.b } | 
| yellowfive@57 | 48 end | 
| yellowfive@57 | 49 | 
| yellowfive@57 | 50 -- helper to take 0-1 value and turn into 2-digit hex value | 
| yellowfive@57 | 51 local function decToHex(num) | 
| yellowfive@57 | 52 	num = math.ceil(num * 255) | 
| yellowfive@57 | 53 	num = string.format("%X", num) | 
| yellowfive@57 | 54 	if string.len(num) == 1 then num = "0" .. num end | 
| yellowfive@57 | 55 	return num | 
| yellowfive@57 | 56 end | 
| yellowfive@57 | 57 | 
| yellowfive@57 | 58 function Amr.ColorToHex(color, alpha) | 
| yellowfive@57 | 59 	return decToHex(alpha) .. decToHex(color.R) .. decToHex(color.G) .. decToHex(color.B) | 
| yellowfive@57 | 60 end | 
| yellowfive@57 | 61 | 
| yellowfive@57 | 62 local function getFontPath(style) | 
| yellowfive@73 | 63 	local locale = GetLocale() | 
| yellowfive@73 | 64 	if locale == "koKR" then | 
| yellowfive@73 | 65 		return "Fonts\\2002.TTF" | 
| yellowfive@73 | 66 	elseif locale == "zhCN" then | 
| yellowfive@73 | 67 		return "Fonts\\ARKai_T.ttf" | 
| yellowfive@73 | 68 	elseif locale == "zhTW" then | 
| yellowfive@73 | 69 		return "Fonts\\bLEI00D.ttf" | 
| yellowfive@73 | 70 	elseif locale == "ruRU" then | 
| yellowfive@73 | 71 		return "Fonts\\FRIZQT___CYR.TTF" | 
| yellowfive@67 | 72 	else | 
| yellowfive@67 | 73 		return "Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\Ubuntu-" .. style .. ".ttf" | 
| yellowfive@67 | 74 	end | 
| yellowfive@57 | 75 end | 
| yellowfive@57 | 76 | 
| yellowfive@57 | 77 -- create a font with the specified style (Regular, Bold, Italic), size (pixels, max of 32), color (object with R, G, B), and alpha (if not specified, defaults to 1) | 
| yellowfive@57 | 78 function Amr.CreateFont(style, size, color, a) | 
| yellowfive@57 | 79 	local alpha = a or 1 | 
| yellowfive@57 | 80 	local id = string.format("%s_%d_%f_%f_%f_%f", style, size, color.R, color.G, color.B, alpha) | 
| yellowfive@57 | 81 	local font = CreateFont(id) | 
| yellowfive@57 | 82 	font:SetFont(getFontPath(style), size) | 
| yellowfive@57 | 83 	font:SetTextColor(color.R, color.G, color.B, alpha) | 
| yellowfive@57 | 84 	return font | 
| yellowfive@57 | 85 end | 
| yellowfive@57 | 86 | 
| yellowfive@57 | 87 -- helper to create a solid texture from a color with R,G,B properties | 
| yellowfive@57 | 88 function Amr.CreateTexture(parent, color, alpha, layer) | 
| yellowfive@57 | 89 	local t = parent:CreateTexture(nil, layer or "ARTWORK") | 
| yellowfive@81 | 90 	t:SetColorTexture(color.R, color.G, color.B, alpha or 1) | 
| yellowfive@57 | 91 	return t | 
| yellowfive@57 | 92 end | 
| yellowfive@57 | 93 | 
| yellowfive@57 | 94 -- helper to create a cheater shadow without having to create custom images | 
| yellowfive@57 | 95 function Amr.DropShadow(frame) | 
| yellowfive@57 | 96 	local shadow = frame:CreateTexture(nil, "BACKGROUND") | 
| yellowfive@81 | 97 	shadow:SetColorTexture(0, 0, 0, 0.4) | 
| yellowfive@57 | 98 	shadow:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -2) | 
| yellowfive@57 | 99 	shadow:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 1, -1) | 
| yellowfive@57 | 100 | 
| yellowfive@57 | 101 	shadow = frame:CreateTexture(nil, "BACKGROUND") | 
| yellowfive@81 | 102 	shadow:SetColorTexture(0, 0, 0, 0.3) | 
| yellowfive@57 | 103 	shadow:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -2) | 
| yellowfive@57 | 104 	shadow:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 2, -2) | 
| yellowfive@57 | 105 | 
| yellowfive@57 | 106 	shadow = frame:CreateTexture(nil, "BACKGROUND") | 
| yellowfive@81 | 107 	shadow:SetColorTexture(0, 0, 0, 0.1) | 
| yellowfive@57 | 108 	shadow:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -2) | 
| yellowfive@57 | 109 	shadow:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 3, -3) | 
| yellowfive@57 | 110 end | 
| yellowfive@57 | 111 | 
| yellowfive@57 | 112 | 
| yellowfive@57 | 113 -- a layout that does nothing, just lets the children position themselves how they prefer | 
| yellowfive@57 | 114 AceGUI:RegisterLayout("None", function(content, children) | 
| yellowfive@57 | 115 	if content.obj.LayoutFinished then | 
| yellowfive@57 | 116 		content.obj:LayoutFinished(nil, nil) | 
| yellowfive@57 | 117 	end | 
| yellowfive@57 | 118 end) | 
| yellowfive@57 | 119 | 
| yellowfive@57 | 120 local _mainFrame = nil | 
| yellowfive@57 | 121 local _mainTabs = nil | 
| yellowfive@57 | 122 local _mainCover = nil | 
| yellowfive@57 | 123 local _activeTab = "Export" | 
| yellowfive@57 | 124 | 
| yellowfive@57 | 125 -- release everything when the UI is closed | 
| yellowfive@57 | 126 local function onMainFrameClose(widget) | 
| yellowfive@57 | 127 	AceGUI:Release(widget) | 
| yellowfive@57 | 128 	Amr["ReleaseTab" .. _activeTab](Amr) | 
| yellowfive@57 | 129 	_mainFrame = nil | 
| yellowfive@57 | 130 	_mainTabs = nil | 
| yellowfive@57 | 131 	_mainCover = nil | 
| yellowfive@57 | 132 end | 
| yellowfive@57 | 133 | 
| yellowfive@57 | 134 local function onMainTabSelected(container, event, group) | 
| yellowfive@57 | 135 	container:ReleaseChildren() | 
| yellowfive@57 | 136 	Amr["ReleaseTab" .. _activeTab](Amr) | 
| yellowfive@57 | 137 | 
| yellowfive@57 | 138 	_activeTab = group | 
| yellowfive@57 | 139 | 
| yellowfive@57 | 140 	-- each section defines its own render method in a separate file (options tab is defined in Core.lua, uses standard Ace config stuff to auto-generate) | 
| yellowfive@57 | 141 	Amr["RenderTab" .. group](Amr, container) | 
| yellowfive@57 | 142 end | 
| yellowfive@57 | 143 | 
| yellowfive@57 | 144 -- refresh the currently displayed tab | 
| yellowfive@57 | 145 function Amr:RefreshTab() | 
| yellowfive@57 | 146 	if not _mainTabs then return end | 
| yellowfive@57 | 147 | 
| yellowfive@57 | 148 	_mainTabs:ReleaseChildren() | 
| yellowfive@57 | 149 	Amr["ReleaseTab" .. _activeTab](Amr) | 
| yellowfive@57 | 150 	Amr["RenderTab" .. _activeTab](Amr, container) | 
| yellowfive@57 | 151 end | 
| yellowfive@57 | 152 | 
| yellowfive@57 | 153 local function createMainWindow() | 
| yellowfive@57 | 154 | 
| yellowfive@57 | 155 	local f = AceGUI:Create("AmrUiFrame") | 
| yellowfive@57 | 156 	f:SetStatusTable(Amr.db.profile.window) -- window position is remembered in db | 
| yellowfive@57 | 157 	f:SetCallback("OnClose", onMainFrameClose) | 
| yellowfive@57 | 158 	f:SetLayout("None") | 
| yellowfive@57 | 159 	f:SetWidth(1000) | 
| yellowfive@57 | 160 	f:SetHeight(700) | 
| yellowfive@57 | 161 	f:SetBorderColor(Amr.Colors.BorderBlue) | 
| yellowfive@57 | 162 	f:SetBackgroundColor(Amr.Colors.Bg) | 
| yellowfive@61 | 163 | 
| yellowfive@61 | 164 	if Amr.db.profile.options.uiScale ~= 1 then | 
| yellowfive@61 | 165 		local scale = tonumber(Amr.db.profile.options.uiScale) | 
| yellowfive@61 | 166 		f:SetScale(scale) | 
| yellowfive@61 | 167 	end | 
| yellowfive@57 | 168 | 
| yellowfive@57 | 169 	-- some status text | 
| yellowfive@57 | 170 	local lblStatus = AceGUI:Create("AmrUiLabel") | 
| yellowfive@57 | 171 	lblStatus:SetWidth(900) | 
| yellowfive@57 | 172 	lblStatus:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan)) | 
| yellowfive@57 | 173 	lblStatus:SetText("Ask Mr. Robot " .. L.MainStatusText("v" .. GetAddOnMetadata(Amr.ADDON_NAME, "Version"), "http://www.askmrrobot.com/wow/addon")) | 
| yellowfive@57 | 174 	lblStatus:SetJustifyH("CENTER") | 
| yellowfive@57 | 175 	lblStatus:SetWordWrap(false) | 
| yellowfive@57 | 176 	lblStatus:SetPoint("TOP", f.content, "BOTTOM") | 
| yellowfive@57 | 177 	f:AddChild(lblStatus) | 
| yellowfive@57 | 178 | 
| yellowfive@57 | 179 	-- create the main UI container | 
| yellowfive@57 | 180 	local c = AceGUI:Create("AmrUiPanel") | 
| yellowfive@57 | 181 	c:SetLayout("Fill") | 
| yellowfive@57 | 182 	c:SetBackgroundColor(Amr.Colors.Black, 0) | 
| yellowfive@57 | 183 	c:SetPoint("TOPLEFT", f.content, "TOPLEFT") | 
| yellowfive@57 | 184 	c:SetPoint("BOTTOMRIGHT", f.content, "BOTTOMRIGHT") | 
| yellowfive@57 | 185 	f:AddChild(c) | 
| yellowfive@57 | 186 | 
| yellowfive@57 | 187 	-- create the main tab strip | 
| yellowfive@57 | 188 	local t =  AceGUI:Create("AmrUiTabGroup") | 
| yellowfive@57 | 189 	t:SetLayout("None") | 
| yellowfive@57 | 190 	t:SetTabs({ | 
| yellowfive@57 | 191 		{text=L.TabExportText, value="Export"}, | 
| yellowfive@57 | 192 		{text=L.TabGearText, value="Gear"}, | 
| yellowfive@57 | 193 		{text=L.TabLogText, value="Log"}, | 
| yellowfive@57 | 194 		{text=L.TabTeamText, value="Team"}, | 
| yellowfive@57 | 195 		{text=L.TabOptionsText, value="Options"} | 
| yellowfive@57 | 196 	}) | 
| yellowfive@57 | 197 	t:SetCallback("OnGroupSelected", onMainTabSelected) | 
| yellowfive@57 | 198 	c:AddChild(t) | 
| yellowfive@57 | 199 | 
| yellowfive@57 | 200 	-- create the cover/overlay container | 
| yellowfive@57 | 201 	c = AceGUI:Create("AmrUiPanel") | 
| yellowfive@57 | 202 	c:SetLayout("None") | 
| yellowfive@57 | 203 	c:EnableMouse(true) | 
| yellowfive@57 | 204 	c:SetBackgroundColor(Amr.Colors.Black, 0.75) | 
| yellowfive@57 | 205 	c:SetPoint("TOPLEFT", f.frame, "TOPLEFT") | 
| yellowfive@57 | 206 	c:SetPoint("BOTTOMRIGHT", f.frame, "BOTTOMRIGHT") | 
| yellowfive@57 | 207 	f:AddChild(c) | 
| yellowfive@57 | 208 | 
| yellowfive@57 | 209 	-- after adding, set cover to sit on top of everything, then hide it | 
| yellowfive@57 | 210 	c:SetStrata("FULLSCREEN_DIALOG") | 
| yellowfive@57 | 211 	c:SetLevel(Amr.FrameLevels.High) | 
| yellowfive@57 | 212 	c:SetVisible(false) | 
| yellowfive@57 | 213 | 
| yellowfive@57 | 214 	-- put standard cover ui elements (label, cancel button) | 
| yellowfive@57 | 215 	local coverMsg = AceGUI:Create("AmrUiLabel") | 
| yellowfive@57 | 216 	coverMsg:SetWidth(600) | 
| yellowfive@57 | 217 	coverMsg:SetFont(Amr.CreateFont("Regular", 16, Amr.Colors.TextTan)) | 
| yellowfive@57 | 218 	coverMsg:SetJustifyH("MIDDLE") | 
| yellowfive@57 | 219 	coverMsg:SetJustifyV("MIDDLE") | 
| yellowfive@57 | 220 	coverMsg:SetText("") | 
| yellowfive@57 | 221 	coverMsg:SetPoint("CENTER", c.frame, "CENTER", 0, 20) | 
| yellowfive@57 | 222 	c:AddChild(coverMsg) | 
| yellowfive@57 | 223 | 
| yellowfive@57 | 224 	local coverCancel = AceGUI:Create("AmrUiTextButton") | 
| yellowfive@57 | 225 	coverCancel:SetWidth(200) | 
| yellowfive@57 | 226 	coverCancel:SetHeight(20) | 
| yellowfive@57 | 227 	coverCancel:SetText(L.CoverCancel) | 
| yellowfive@57 | 228 	coverCancel:SetFont(Amr.CreateFont("Italic", 14, Amr.Colors.TextHeaderDisabled)) | 
| yellowfive@57 | 229 	coverCancel:SetHoverFont(Amr.CreateFont("Italic", 14, Amr.Colors.TextHeaderActive)) | 
| yellowfive@57 | 230 	coverCancel:SetPoint("CENTER", c.frame, "CENTER", 0, -20) | 
| yellowfive@57 | 231 	c:AddChild(coverCancel) | 
| yellowfive@57 | 232 | 
| yellowfive@57 | 233 	coverCancel:SetCallback("OnClick", function(widget) | 
| yellowfive@57 | 234 		Amr:HideCover() | 
| yellowfive@57 | 235 	end) | 
| yellowfive@57 | 236 | 
| yellowfive@57 | 237 	-- create cover content area for custom cover ui (sort of like a modal dialog) | 
| yellowfive@57 | 238 	local coverContent = AceGUI:Create("AmrUiPanel") | 
| yellowfive@57 | 239 	coverContent:SetLayout("None") | 
| yellowfive@57 | 240 	coverContent:SetBackgroundColor(Amr.Colors.Black, 0) | 
| yellowfive@57 | 241 	coverContent:SetPoint("TOPLEFT", c.frame, "TOPLEFT") | 
| yellowfive@57 | 242 	coverContent:SetPoint("BOTTOMRIGHT", c.frame, "BOTTOMRIGHT") | 
| yellowfive@57 | 243 	c:AddChild(coverContent) | 
| yellowfive@57 | 244 | 
| yellowfive@57 | 245 	_mainFrame = f | 
| yellowfive@57 | 246 	_mainTabs = t | 
| yellowfive@57 | 247 	_mainCover = { | 
| yellowfive@57 | 248 		panel   = c, | 
| yellowfive@57 | 249 		content = coverContent, | 
| yellowfive@57 | 250 		label   = coverMsg, | 
| yellowfive@57 | 251 		cancel  = coverCancel | 
| yellowfive@57 | 252 	} | 
| yellowfive@57 | 253 end | 
| yellowfive@57 | 254 | 
| yellowfive@57 | 255 function Amr:ShowCover(msgOrRenderFunc, disableCancel) | 
| yellowfive@57 | 256 	if _mainCover then | 
| yellowfive@57 | 257 		_mainCover.panel:SetVisible(true) | 
| yellowfive@57 | 258 | 
| yellowfive@57 | 259 		if type(msgOrRenderFunc) == "function" then | 
| yellowfive@57 | 260 			_mainCover.label:SetText("") | 
| yellowfive@57 | 261 			_mainCover.cancel:SetVisible(false) | 
| yellowfive@57 | 262 | 
| yellowfive@57 | 263 			-- render custom content into the cover | 
| yellowfive@57 | 264 			msgOrRenderFunc(_mainCover.content) | 
| yellowfive@57 | 265 		else | 
| yellowfive@57 | 266 			-- standard loading/waiting message with optional cancel button | 
| yellowfive@57 | 267 			_mainCover.label:SetText(msgOrRenderFunc or "") | 
| yellowfive@57 | 268 			_mainCover.cancel:SetVisible(not disableCancel) | 
| yellowfive@57 | 269 		end | 
| yellowfive@57 | 270 	end | 
| yellowfive@57 | 271 end | 
| yellowfive@57 | 272 | 
| yellowfive@57 | 273 function Amr:HideCover() | 
| yellowfive@57 | 274 	if _mainCover then | 
| yellowfive@57 | 275 		_mainCover.panel:SetVisible(false) | 
| yellowfive@57 | 276 | 
| yellowfive@57 | 277 		-- release any custom content rendered into the cover | 
| yellowfive@57 | 278 		_mainCover.content:ReleaseChildren() | 
| yellowfive@57 | 279 	end | 
| yellowfive@57 | 280 end | 
| yellowfive@57 | 281 | 
| yellowfive@57 | 282 -- shows a "modal" alert over the main UI | 
| yellowfive@57 | 283 function Amr:ShowAlert(message, btnText) | 
| yellowfive@57 | 284 | 
| yellowfive@57 | 285 	Amr:ShowCover(function(container) | 
| yellowfive@57 | 286 		local border = AceGUI:Create("AmrUiPanel") | 
| yellowfive@57 | 287 		border:SetLayout("None") | 
| yellowfive@57 | 288 		border:SetBackgroundColor(Amr.Colors.BorderBlue) | 
| yellowfive@57 | 289 		border:SetWidth(400) | 
| yellowfive@57 | 290 		border:SetHeight(150) | 
| yellowfive@57 | 291 		border:SetPoint("CENTER", container.frame, "CENTER") | 
| yellowfive@57 | 292 		container:AddChild(border) | 
| yellowfive@57 | 293 | 
| yellowfive@57 | 294 		local bg = AceGUI:Create("AmrUiPanel") | 
| yellowfive@57 | 295 		bg:SetLayout("None") | 
| yellowfive@57 | 296 		bg:SetBackgroundColor(Amr.Colors.Bg) | 
| yellowfive@57 | 297 		bg:SetPoint("TOPLEFT", border.frame, "TOPLEFT", 1, -1) | 
| yellowfive@57 | 298 		bg:SetPoint("BOTTOMRIGHT", border.frame, "BOTTOMRIGHT", -1, 1) | 
| yellowfive@57 | 299 		border:AddChild(bg) | 
| yellowfive@57 | 300 | 
| yellowfive@57 | 301 		local lbl = AceGUI:Create("AmrUiLabel") | 
| yellowfive@57 | 302 		lbl:SetWidth(360) | 
| yellowfive@57 | 303 		lbl:SetFont(Amr.CreateFont("Regular", 16, Amr.Colors.Text)) | 
| yellowfive@57 | 304 		lbl:SetJustifyH("CENTER") | 
| yellowfive@57 | 305 		lbl:SetText(message) | 
| yellowfive@57 | 306 		lbl:SetPoint("TOP", bg.content, "TOP", 0, -20) | 
| yellowfive@57 | 307 		bg:AddChild(lbl) | 
| yellowfive@57 | 308 | 
| yellowfive@57 | 309 		local btn = AceGUI:Create("AmrUiButton") | 
| yellowfive@57 | 310 		btn:SetBackgroundColor(Amr.Colors.Orange) | 
| yellowfive@57 | 311 		btn:SetFont(Amr.CreateFont("Bold", 16, Amr.Colors.White)) | 
| yellowfive@57 | 312 		btn:SetWidth(120) | 
| yellowfive@57 | 313 		btn:SetHeight(26) | 
| yellowfive@57 | 314 		btn:SetText(btnText) | 
| yellowfive@57 | 315 		btn:SetPoint("BOTTOM", bg.content, "BOTTOM", 0, 20) | 
| yellowfive@57 | 316 		bg:AddChild(btn) | 
| yellowfive@57 | 317 | 
| yellowfive@57 | 318 		btn:SetCallback("OnClick", function(widget) | 
| yellowfive@57 | 319 			Amr:HideCover() | 
| yellowfive@57 | 320 		end) | 
| yellowfive@57 | 321 	end) | 
| yellowfive@57 | 322 end | 
| yellowfive@57 | 323 | 
| yellowfive@57 | 324 -- toggle visibility of the UI | 
| yellowfive@57 | 325 function Amr:Toggle() | 
| yellowfive@57 | 326 	if not self:IsEnabled() then return end | 
| yellowfive@57 | 327 | 
| yellowfive@57 | 328 	if not _mainFrame then | 
| yellowfive@57 | 329 		self:Show() | 
| yellowfive@57 | 330 	else | 
| yellowfive@57 | 331 		self:Hide() | 
| yellowfive@57 | 332 	end | 
| yellowfive@57 | 333 end | 
| yellowfive@57 | 334 | 
| yellowfive@57 | 335 -- hide the UI if not already hidden | 
| yellowfive@57 | 336 function Amr:Hide() | 
| yellowfive@57 | 337 	if not self:IsEnabled() then return end | 
| yellowfive@57 | 338 	if not _mainFrame then return end | 
| yellowfive@57 | 339 | 
| yellowfive@57 | 340 	_mainFrame:Hide() | 
| yellowfive@57 | 341 end | 
| yellowfive@57 | 342 | 
| yellowfive@57 | 343 -- show the UI if not shown already, and display the last active tab | 
| yellowfive@57 | 344 function Amr:Show() | 
| yellowfive@57 | 345 	if not self:IsEnabled() then return end | 
| yellowfive@57 | 346 | 
| yellowfive@57 | 347 	if _mainFrame then | 
| yellowfive@57 | 348 		_mainFrame:Show() | 
| yellowfive@57 | 349 	else | 
| yellowfive@57 | 350 		createMainWindow() | 
| yellowfive@57 | 351 	end | 
| yellowfive@57 | 352 | 
| yellowfive@57 | 353 	-- show the active tab | 
| yellowfive@57 | 354 	_mainTabs:SelectTab(_activeTab) | 
| yellowfive@57 | 355 end | 
| yellowfive@57 | 356 | 
| yellowfive@61 | 357 function Amr:Reset() | 
| yellowfive@61 | 358 	if not self:IsEnabled() then return end | 
| yellowfive@61 | 359 | 
| yellowfive@61 | 360 	Amr:Hide() | 
| yellowfive@61 | 361 	Amr:HideLootWindow() | 
| yellowfive@61 | 362 	Amr:HideShopWindow() | 
| yellowfive@61 | 363 	Amr.db.profile.options.uiScale = 1 | 
| yellowfive@61 | 364 	Amr.db.profile.window = {} | 
| yellowfive@61 | 365 	Amr.db.profile.lootWindow = {} | 
| yellowfive@61 | 366 	Amr.db.profile.shopWindow = {} | 
| yellowfive@61 | 367 end | 
| yellowfive@61 | 368 | 
| yellowfive@57 | 369 -- show the UI if not shown already, and select the specified tab | 
| yellowfive@57 | 370 function Amr:ShowTab(tab) | 
| yellowfive@57 | 371 	if not self:IsEnabled() then return end | 
| yellowfive@57 | 372 | 
| yellowfive@57 | 373 	_activeTab = tab | 
| yellowfive@57 | 374 	self:Show() | 
| yellowfive@57 | 375 end | 
| yellowfive@57 | 376 | 
| yellowfive@57 | 377 ---------------------------------------------------------------------------------------- | 
| yellowfive@57 | 378 -- Tooltips | 
| yellowfive@57 | 379 ---------------------------------------------------------------------------------------- | 
| yellowfive@57 | 380 | 
| yellowfive@57 | 381 -- set an item tooltip on any AceGUI widget with OnEnter and OnLeave events | 
| yellowfive@57 | 382 function Amr:SetItemTooltip(obj, itemLink, anchor, x, y) | 
| yellowfive@57 | 383 	obj:SetUserData("ttItemLink", itemLink) | 
| yellowfive@57 | 384 	obj:SetCallback("OnEnter", function(widget) | 
| yellowfive@57 | 385 		local tooltipLink = widget:GetUserData("ttItemLink") | 
| yellowfive@57 | 386 		GameTooltip:SetOwner(widget.frame, anchor and anchor or "ANCHOR_CURSOR", x, y) | 
| yellowfive@57 | 387 		GameTooltip:SetHyperlink(tooltipLink) | 
| yellowfive@57 | 388 	end) | 
| yellowfive@57 | 389 	obj:SetCallback("OnLeave", function(widget) | 
| yellowfive@57 | 390 		GameTooltip:Hide() | 
| yellowfive@57 | 391 	end) | 
| yellowfive@57 | 392 end | 
| yellowfive@57 | 393 | 
| yellowfive@57 | 394 function Amr:SetSpellTooltip(obj, spellId, anchor, x, y) | 
| yellowfive@57 | 395 	obj:SetUserData("ttSpellId", spellId) | 
| yellowfive@57 | 396 	obj:SetCallback("OnEnter", function(widget) | 
| yellowfive@57 | 397 		local ttSpellId = widget:GetUserData("ttSpellId") | 
| yellowfive@57 | 398 		GameTooltip:SetOwner(widget.frame, anchor and anchor or "ANCHOR_CURSOR", x, y) | 
| yellowfive@57 | 399 		GameTooltip:SetSpellByID(ttSpellId) | 
| yellowfive@57 | 400 	end) | 
| yellowfive@57 | 401 	obj:SetCallback("OnLeave", function(widget) | 
| yellowfive@57 | 402 		GameTooltip:Hide() | 
| yellowfive@57 | 403 	end) | 
| yellowfive@57 | 404 end | 
| yellowfive@57 | 405 | 
| yellowfive@57 | 406 function Amr:RenderCoverChrome(container, width, height) | 
| yellowfive@57 | 407 | 
| yellowfive@57 | 408 	local border = AceGUI:Create("AmrUiPanel") | 
| yellowfive@57 | 409 	border:SetLayout("None") | 
| yellowfive@57 | 410 	border:SetBackgroundColor(Amr.Colors.BorderBlue) | 
| yellowfive@57 | 411 	border:SetWidth(width + 2) | 
| yellowfive@57 | 412 	border:SetHeight(height + 2) | 
| yellowfive@57 | 413 	border:SetPoint("CENTER", container.frame, "CENTER") | 
| yellowfive@57 | 414 	container:AddChild(border) | 
| yellowfive@57 | 415 | 
| yellowfive@57 | 416 	local bg = AceGUI:Create("AmrUiPanel") | 
| yellowfive@57 | 417 	bg:SetLayout("None") | 
| yellowfive@57 | 418 	bg:SetBackgroundColor(Amr.Colors.Bg) | 
| yellowfive@57 | 419 	bg:SetPoint("TOPLEFT", border.frame, "TOPLEFT", 1, -1) | 
| yellowfive@57 | 420 	bg:SetPoint("BOTTOMRIGHT", border.frame, "BOTTOMRIGHT", -1, 1) | 
| yellowfive@57 | 421 	border:AddChild(bg) | 
| yellowfive@57 | 422 | 
| yellowfive@57 | 423 	return bg, border | 
| yellowfive@57 | 424 end |