annotate Libs/DF/fw.lua @ 11:2f09fe4be15c

Added an Options Panel.
author Tercio
date Mon, 20 Apr 2015 16:34:18 -0300
parents
children 0c160948ac5e
rev   line source
Tercio@11 1
Tercio@11 2 local major, minor = "DetailsFramework-1.0", 2
Tercio@11 3 local DF, oldminor = LibStub:NewLibrary (major, minor)
Tercio@11 4
Tercio@11 5
Tercio@11 6 if (not DF) then
Tercio@11 7 return
Tercio@11 8 end
Tercio@11 9
Tercio@11 10 local _type = type
Tercio@11 11 local _unpack = unpack
Tercio@11 12 local _
Tercio@11 13 local upper = string.upper
Tercio@11 14
Tercio@11 15 DF.LabelNameCounter = 1
Tercio@11 16 DF.PictureNameCounter = 1
Tercio@11 17 DF.BarNameCounter = 1
Tercio@11 18 DF.DropDownCounter = 1
Tercio@11 19 DF.PanelCounter = 1
Tercio@11 20 DF.ButtonCounter = 1
Tercio@11 21 DF.SliderCounter = 1
Tercio@11 22 DF.SplitBarCounter = 1
Tercio@11 23
Tercio@11 24 do
Tercio@11 25 local path = string.match (debugstack (1, 1, 0), "AddOns\\(.+)fw.lua")
Tercio@11 26 if (path) then
Tercio@11 27 DF.folder = "Interface\\AddOns\\" .. path
Tercio@11 28 else
Tercio@11 29 DF.folder = ""
Tercio@11 30 end
Tercio@11 31 end
Tercio@11 32
Tercio@11 33 DF.debug = false
Tercio@11 34
Tercio@11 35 _G ["DetailsFramework"] = DF
Tercio@11 36
Tercio@11 37 DF.embeds = DF.embeds or {}
Tercio@11 38 local embed_functions = {
Tercio@11 39 "SetFontSize",
Tercio@11 40 "SetFontFace",
Tercio@11 41 "SetFontColor",
Tercio@11 42 "GetFontSize",
Tercio@11 43 "GetFontFace",
Tercio@11 44 "trim",
Tercio@11 45 "Msg",
Tercio@11 46 "CreateFlashAnimation",
Tercio@11 47 "Fade",
Tercio@11 48 "NewColor",
Tercio@11 49 "IsHtmlColor",
Tercio@11 50 "ParseColors",
Tercio@11 51 "BuildMenu",
Tercio@11 52 "ShowTutorialAlertFrame",
Tercio@11 53 "GetNpcIdFromGuid",
Tercio@11 54 "ShowFeedbackPanel",
Tercio@11 55
Tercio@11 56 "CreateDropDown",
Tercio@11 57 "CreateButton",
Tercio@11 58 "CreateColorPickButton",
Tercio@11 59 "CreateLabel",
Tercio@11 60 "CreateBar",
Tercio@11 61 "CreatePanel",
Tercio@11 62 "CreateFillPanel",
Tercio@11 63 "ColorPick",
Tercio@11 64 "IconPick",
Tercio@11 65 "CreateSimplePanel",
Tercio@11 66 "CreateChartPanel",
Tercio@11 67 "CreateImage",
Tercio@11 68 "CreateScrollBar",
Tercio@11 69 "CreateSwitch",
Tercio@11 70 "CreateSlider",
Tercio@11 71 "CreateSplitBar",
Tercio@11 72 "CreateTextEntry",
Tercio@11 73 "Create1PxPanel",
Tercio@11 74 "CreateFeedbackButton",
Tercio@11 75
Tercio@11 76 "www_icons",
Tercio@11 77 }
Tercio@11 78
Tercio@11 79 DF.www_icons = {
Tercio@11 80 texture = "feedback_sites",
Tercio@11 81 wowi = {0, 0.7890625, 0, 37/128},
Tercio@11 82 curse = {0, 0.7890625, 38/123, 79/128},
Tercio@11 83 mmoc = {0, 0.7890625, 80/123, 123/128},
Tercio@11 84 }
Tercio@11 85
Tercio@11 86 function DF:Embed (target)
Tercio@11 87 for k, v in pairs (embed_functions) do
Tercio@11 88 target[v] = self[v]
Tercio@11 89 end
Tercio@11 90 self.embeds [target] = true
Tercio@11 91 return target
Tercio@11 92 end
Tercio@11 93
Tercio@11 94 function DF:SetFontSize (fontString, ...)
Tercio@11 95 local fonte, _, flags = fontString:GetFont()
Tercio@11 96 fontString:SetFont (fonte, max (...), flags)
Tercio@11 97 end
Tercio@11 98 function DF:SetFontFace (fontString, fontface)
Tercio@11 99 local _, size, flags = fontString:GetFont()
Tercio@11 100 fontString:SetFont (fontface, size, flags)
Tercio@11 101 end
Tercio@11 102 function DF:SetFontColor (fontString, r, g, b, a)
Tercio@11 103 r, g, b, a = DF:ParseColors (r, g, b, a)
Tercio@11 104 fontString:SetTextColor (r, g, b, a)
Tercio@11 105 end
Tercio@11 106
Tercio@11 107 function DF:GetFontSize (fontString)
Tercio@11 108 local _, size = fontString:GetFont()
Tercio@11 109 return size
Tercio@11 110 end
Tercio@11 111 function DF:GetFontFace (fontString)
Tercio@11 112 local fontface = fontString:GetFont()
Tercio@11 113 return fontface
Tercio@11 114 end
Tercio@11 115
Tercio@11 116 function DF:SetFontOutline (fontString, outline)
Tercio@11 117 local fonte, size = fontString:GetFont()
Tercio@11 118 if (outline) then
Tercio@11 119 if (_type (outline) == "boolean" and outline) then
Tercio@11 120 outline = "OUTLINE"
Tercio@11 121 elseif (outline == 1) then
Tercio@11 122 outline = "OUTLINE"
Tercio@11 123 elseif (outline == 2) then
Tercio@11 124 outline = "THICKOUTLINE"
Tercio@11 125 end
Tercio@11 126 end
Tercio@11 127
Tercio@11 128 fontString:SetFont (fonte, size, outline)
Tercio@11 129 end
Tercio@11 130
Tercio@11 131 function DF:trim (s)
Tercio@11 132 local from = s:match"^%s*()"
Tercio@11 133 return from > #s and "" or s:match(".*%S", from)
Tercio@11 134 end
Tercio@11 135
Tercio@11 136 function DF:Msg (msg)
Tercio@11 137 print ("|cFFFFFFAA" .. self.__name .. "|r " .. msg)
Tercio@11 138 end
Tercio@11 139
Tercio@11 140 function DF:GetNpcIdFromGuid (guid)
Tercio@11 141 local NpcId = select ( 6, strsplit ( "-", guid ) )
Tercio@11 142 if (NpcId) then
Tercio@11 143 return tonumber ( NpcId )
Tercio@11 144 end
Tercio@11 145 return 0
Tercio@11 146 end
Tercio@11 147
Tercio@11 148 local onFinish = function (self)
Tercio@11 149 if (self.showWhenDone) then
Tercio@11 150 self.frame:SetAlpha (1)
Tercio@11 151 else
Tercio@11 152 self.frame:SetAlpha (0)
Tercio@11 153 self.frame:Hide()
Tercio@11 154 end
Tercio@11 155
Tercio@11 156 if (self.onFinishFunc) then
Tercio@11 157 self:onFinishFunc (self.frame)
Tercio@11 158 end
Tercio@11 159 end
Tercio@11 160
Tercio@11 161 local stop = function (self)
Tercio@11 162 local FlashAnimation = self.FlashAnimation
Tercio@11 163 FlashAnimation:Stop()
Tercio@11 164 end
Tercio@11 165
Tercio@11 166 local flash = function (self, fadeInTime, fadeOutTime, flashDuration, showWhenDone, flashInHoldTime, flashOutHoldTime, loopType)
Tercio@11 167
Tercio@11 168 local FlashAnimation = self.FlashAnimation
Tercio@11 169
Tercio@11 170 local fadeIn = FlashAnimation.fadeIn
Tercio@11 171 local fadeOut = FlashAnimation.fadeOut
Tercio@11 172
Tercio@11 173 fadeIn:Stop()
Tercio@11 174 fadeOut:Stop()
Tercio@11 175
Tercio@11 176 fadeIn:SetDuration (fadeInTime or 1)
Tercio@11 177 fadeIn:SetEndDelay (flashInHoldTime or 0)
Tercio@11 178
Tercio@11 179 fadeOut:SetDuration (fadeOutTime or 1)
Tercio@11 180 fadeOut:SetEndDelay (flashOutHoldTime or 0)
Tercio@11 181
Tercio@11 182 FlashAnimation.duration = flashDuration
Tercio@11 183 FlashAnimation.loopTime = FlashAnimation:GetDuration()
Tercio@11 184 FlashAnimation.finishAt = GetTime() + flashDuration
Tercio@11 185 FlashAnimation.showWhenDone = showWhenDone
Tercio@11 186
Tercio@11 187 FlashAnimation:SetLooping (loopType or "REPEAT")
Tercio@11 188
Tercio@11 189 self:Show()
Tercio@11 190 self:SetAlpha (0)
Tercio@11 191 FlashAnimation:Play()
Tercio@11 192 end
Tercio@11 193
Tercio@11 194 function DF:CreateFlashAnimation (frame, onFinishFunc, onLoopFunc)
Tercio@11 195 local FlashAnimation = frame:CreateAnimationGroup()
Tercio@11 196
Tercio@11 197 FlashAnimation.fadeOut = FlashAnimation:CreateAnimation ("Alpha") --> fade out anime
Tercio@11 198 FlashAnimation.fadeOut:SetOrder (1)
Tercio@11 199 FlashAnimation.fadeOut:SetChange (1)
Tercio@11 200
Tercio@11 201 FlashAnimation.fadeIn = FlashAnimation:CreateAnimation ("Alpha") --> fade in anime
Tercio@11 202 FlashAnimation.fadeIn:SetOrder (2)
Tercio@11 203 FlashAnimation.fadeIn:SetChange (-1)
Tercio@11 204
Tercio@11 205 frame.FlashAnimation = FlashAnimation
Tercio@11 206 FlashAnimation.frame = frame
Tercio@11 207 FlashAnimation.onFinishFunc = onFinishFunc
Tercio@11 208
Tercio@11 209 FlashAnimation:SetScript ("OnLoop", onLoopFunc)
Tercio@11 210 FlashAnimation:SetScript ("OnFinished", onFinish)
Tercio@11 211
Tercio@11 212 frame.Flash = flash
Tercio@11 213 frame.Stop = stop
Tercio@11 214 end
Tercio@11 215
Tercio@11 216 -----------------------------------------
Tercio@11 217
Tercio@11 218 local fade_IN_finished_func = function (frame)
Tercio@11 219 if (frame.fading_in) then
Tercio@11 220 frame.hidden = true
Tercio@11 221 frame.faded = true
Tercio@11 222 frame.fading_in = false
Tercio@11 223 frame:Hide()
Tercio@11 224 end
Tercio@11 225 end
Tercio@11 226
Tercio@11 227 local fade_OUT_finished_func = function (frame)
Tercio@11 228 if (frame:IsShown() and frame.fading_out) then
Tercio@11 229 frame.hidden = false
Tercio@11 230 frame.faded = false
Tercio@11 231 frame.fading_out = false
Tercio@11 232 else
Tercio@11 233 frame:SetAlpha(0)
Tercio@11 234 end
Tercio@11 235 end
Tercio@11 236
Tercio@11 237 local just_fade_func = function (frame)
Tercio@11 238 frame.hidden = false
Tercio@11 239 frame.faded = true
Tercio@11 240 frame.fading_in = false
Tercio@11 241 end
Tercio@11 242
Tercio@11 243 local anim_OUT_alpha_func = function (frame)
Tercio@11 244 frame.fading_out = false
Tercio@11 245 end
Tercio@11 246
Tercio@11 247 local anim_IN_alpha_func = function (frame)
Tercio@11 248 frame.fading_in = false
Tercio@11 249 end
Tercio@11 250
Tercio@11 251 function DF:Fade (frame, tipo, velocidade, parametros)
Tercio@11 252
Tercio@11 253 if (_type (frame) == "table") then
Tercio@11 254 if (frame.dframework) then
Tercio@11 255 frame = frame.widget
Tercio@11 256 end
Tercio@11 257 end
Tercio@11 258
Tercio@11 259 velocidade = velocidade or 0.3
Tercio@11 260
Tercio@11 261 if (upper (tipo) == "IN") then
Tercio@11 262
Tercio@11 263 if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then --> ja esta escondida
Tercio@11 264 return
Tercio@11 265 elseif (frame.fading_in) then --> ja esta com uma animação, se for true
Tercio@11 266 return
Tercio@11 267 end
Tercio@11 268
Tercio@11 269 if (frame.fading_out) then --> se tiver uma animação de aparecer em andamento se for true
Tercio@11 270 frame.fading_out = false
Tercio@11 271 end
Tercio@11 272
Tercio@11 273 UIFrameFadeIn (frame, velocidade, frame:GetAlpha(), 0)
Tercio@11 274 frame.fading_in = true
Tercio@11 275
Tercio@11 276 frame.fadeInfo.finishedFunc = fade_IN_finished_func
Tercio@11 277 frame.fadeInfo.finishedArg1 = frame
Tercio@11 278
Tercio@11 279 elseif (upper (tipo) == "OUT") then --> aparecer
Tercio@11 280 if (frame:GetAlpha() == 1 and not frame.hidden and not frame.fading_in) then --> ja esta na tela
Tercio@11 281 return
Tercio@11 282 elseif (frame.fading_out) then --> já ta com fading out
Tercio@11 283 return
Tercio@11 284 end
Tercio@11 285
Tercio@11 286 if (frame.fading_in) then --> se tiver uma animação de hidar em andamento se for true
Tercio@11 287 frame.fading_in = false
Tercio@11 288 end
Tercio@11 289
Tercio@11 290 frame:Show()
Tercio@11 291 UIFrameFadeOut (frame, velocidade, frame:GetAlpha(), 1.0)
Tercio@11 292 frame.fading_out = true
Tercio@11 293
Tercio@11 294 frame.fadeInfo.finishedFunc = fade_OUT_finished_func
Tercio@11 295 frame.fadeInfo.finishedArg1 = frame
Tercio@11 296
Tercio@11 297 elseif (tipo == 0) then --> força o frame a ser mostrado
Tercio@11 298 frame.hidden = false
Tercio@11 299 frame.faded = false
Tercio@11 300 frame.fading_out = false
Tercio@11 301 frame.fading_in = false
Tercio@11 302 frame:Show()
Tercio@11 303 frame:SetAlpha (1)
Tercio@11 304
Tercio@11 305 elseif (tipo == 1) then --> força o frame a ser hidado
Tercio@11 306 frame.hidden = true
Tercio@11 307 frame.faded = true
Tercio@11 308 frame.fading_out = false
Tercio@11 309 frame.fading_in = false
Tercio@11 310 frame:SetAlpha (0)
Tercio@11 311 frame:Hide()
Tercio@11 312
Tercio@11 313 elseif (tipo == -1) then --> apenas da fade sem hidar
Tercio@11 314 if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then --> ja esta escondida
Tercio@11 315 return
Tercio@11 316 elseif (frame.fading_in) then --> ja esta com uma animação, se for true
Tercio@11 317 return
Tercio@11 318 end
Tercio@11 319
Tercio@11 320 if (frame.fading_out) then --> se tiver uma animação de aparecer em andamento se for true
Tercio@11 321 frame.fading_out = false
Tercio@11 322 end
Tercio@11 323
Tercio@11 324 UIFrameFadeIn (frame, velocidade, frame:GetAlpha(), 0)
Tercio@11 325 frame.fading_in = true
Tercio@11 326 frame.fadeInfo.finishedFunc = just_fade_func
Tercio@11 327 frame.fadeInfo.finishedArg1 = frame
Tercio@11 328
Tercio@11 329 elseif (upper (tipo) == "ALPHAANIM") then
Tercio@11 330
Tercio@11 331 local value = velocidade
Tercio@11 332 local currentApha = frame:GetAlpha()
Tercio@11 333 frame:Show()
Tercio@11 334
Tercio@11 335 if (currentApha < value) then
Tercio@11 336 if (frame.fading_in) then --> se tiver uma animação de hidar em andamento se for true
Tercio@11 337 frame.fading_in = false
Tercio@11 338 frame.fadeInfo.finishedFunc = nil
Tercio@11 339 end
Tercio@11 340 UIFrameFadeOut (frame, 0.3, currentApha, value)
Tercio@11 341 frame.fading_out = true
Tercio@11 342
Tercio@11 343 frame.fadeInfo.finishedFunc = anim_OUT_alpha_func
Tercio@11 344 frame.fadeInfo.finishedArg1 = frame
Tercio@11 345
Tercio@11 346 else
Tercio@11 347 if (frame.fading_out) then --> se tiver uma animação de hidar em andamento se for true
Tercio@11 348 frame.fading_out = false
Tercio@11 349 frame.fadeInfo.finishedFunc = nil
Tercio@11 350 end
Tercio@11 351 UIFrameFadeIn (frame, 0.3, currentApha, value)
Tercio@11 352 frame.fading_in = true
Tercio@11 353
Tercio@11 354 frame.fadeInfo.finishedFunc = anim_IN_alpha_func
Tercio@11 355 frame.fadeInfo.finishedArg1 = frame
Tercio@11 356 end
Tercio@11 357
Tercio@11 358 elseif (upper (tipo) == "ALPHA") then --> setando um alpha determinado
Tercio@11 359 if (frame.fading_in or frame.fading_out) then
Tercio@11 360 frame.fadeInfo.finishedFunc = nil
Tercio@11 361 UIFrameFadeIn (frame, velocidade, frame:GetAlpha(), frame:GetAlpha())
Tercio@11 362 end
Tercio@11 363 frame.hidden = false
Tercio@11 364 frame.faded = false
Tercio@11 365 frame.fading_in = false
Tercio@11 366 frame.fading_out = false
Tercio@11 367 frame:Show()
Tercio@11 368 frame:SetAlpha (velocidade)
Tercio@11 369 end
Tercio@11 370 end
Tercio@11 371
Tercio@11 372 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 373 --> points
Tercio@11 374
Tercio@11 375 function DF:CheckPoints (v1, v2, v3, v4, v5, object)
Tercio@11 376
Tercio@11 377 if (not v1 and not v2) then
Tercio@11 378 return "topleft", object.widget:GetParent(), "topleft", 0, 0
Tercio@11 379 end
Tercio@11 380
Tercio@11 381 if (_type (v1) == "string") then
Tercio@11 382 local frameGlobal = _G [v1]
Tercio@11 383 if (frameGlobal and frameGlobal.GetObjectType) then
Tercio@11 384 return DF:CheckPoints (frameGlobal, v2, v3, v4, v5, object)
Tercio@11 385 end
Tercio@11 386
Tercio@11 387 elseif (_type (v2) == "string") then
Tercio@11 388 local frameGlobal = _G [v2]
Tercio@11 389 if (frameGlobal and frameGlobal.GetObjectType) then
Tercio@11 390 return DF:CheckPoints (v1, frameGlobal, v3, v4, v5, object)
Tercio@11 391 end
Tercio@11 392 end
Tercio@11 393
Tercio@11 394 if (_type (v1) == "string" and _type (v2) == "table") then --> :setpoint ("left", frame, _, _, _)
Tercio@11 395 if (not v3 or _type (v3) == "number") then --> :setpoint ("left", frame, 10, 10)
Tercio@11 396 v1, v2, v3, v4, v5 = v1, v2, v1, v3, v4
Tercio@11 397 end
Tercio@11 398
Tercio@11 399 elseif (_type (v1) == "string" and _type (v2) == "number") then --> :setpoint ("topleft", x, y)
Tercio@11 400 v1, v2, v3, v4, v5 = v1, object.widget:GetParent(), v1, v2, v3
Tercio@11 401
Tercio@11 402 elseif (_type (v1) == "number") then --> :setpoint (x, y)
Tercio@11 403 v1, v2, v3, v4, v5 = "topleft", object.widget:GetParent(), "topleft", v1, v2
Tercio@11 404
Tercio@11 405 elseif (_type (v1) == "table") then --> :setpoint (frame, x, y)
Tercio@11 406 v1, v2, v3, v4, v5 = "topleft", v1, "topleft", v2, v3
Tercio@11 407
Tercio@11 408 end
Tercio@11 409
Tercio@11 410 if (not v2) then
Tercio@11 411 v2 = object.widget:GetParent()
Tercio@11 412 elseif (v2.dframework) then
Tercio@11 413 v2 = v2.widget
Tercio@11 414 end
Tercio@11 415
Tercio@11 416 return v1 or "topleft", v2, v3 or "topleft", v4 or 0, v5 or 0
Tercio@11 417 end
Tercio@11 418
Tercio@11 419
Tercio@11 420 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 421 --> colors
Tercio@11 422
Tercio@11 423 function DF:NewColor (_colorname, _colortable, _green, _blue, _alpha)
Tercio@11 424 assert (_type (_colorname) == "string", "NewColor: colorname must be a string.")
Tercio@11 425 assert (not DF.alias_text_colors [_colorname], "NewColor: colorname already exists.")
Tercio@11 426
Tercio@11 427 if (_type (_colortable) == "table") then
Tercio@11 428 if (_colortable[1] and _colortable[2] and _colortable[3]) then
Tercio@11 429 _colortable[4] = _colortable[4] or 1
Tercio@11 430 DF.alias_text_colors [_colorname] = _colortable
Tercio@11 431 else
Tercio@11 432 error ("invalid color table.")
Tercio@11 433 end
Tercio@11 434 elseif (_colortable and _green and _blue) then
Tercio@11 435 _alpha = _alpha or 1
Tercio@11 436 DF.alias_text_colors [_colorname] = {_colortable, _green, _blue, _alpha}
Tercio@11 437 else
Tercio@11 438 error ("invalid parameter.")
Tercio@11 439 end
Tercio@11 440
Tercio@11 441 return true
Tercio@11 442 end
Tercio@11 443
Tercio@11 444 function DF:IsHtmlColor (color)
Tercio@11 445 return DF.alias_text_colors [color]
Tercio@11 446 end
Tercio@11 447
Tercio@11 448 local tn = tonumber
Tercio@11 449 function DF:ParseColors (_arg1, _arg2, _arg3, _arg4)
Tercio@11 450 if (_type (_arg1) == "table") then
Tercio@11 451 _arg1, _arg2, _arg3, _arg4 = _unpack (_arg1)
Tercio@11 452
Tercio@11 453 elseif (_type (_arg1) == "string") then
Tercio@11 454
Tercio@11 455 if (string.find (_arg1, "#")) then
Tercio@11 456 _arg1 = _arg1:gsub ("#","")
Tercio@11 457 if (string.len (_arg1) == 8) then --alpha
Tercio@11 458 _arg1, _arg2, _arg3, _arg4 = tn ("0x" .. _arg1:sub (3, 4))/255, tn ("0x" .. _arg1:sub (5, 6))/255, tn ("0x" .. _arg1:sub (7, 8))/255, tn ("0x" .. _arg1:sub (1, 2))/255
Tercio@11 459 else
Tercio@11 460 _arg1, _arg2, _arg3, _arg4 = tn ("0x" .. _arg1:sub (1, 2))/255, tn ("0x" .. _arg1:sub (3, 4))/255, tn ("0x" .. _arg1:sub (5, 6))/255, 1
Tercio@11 461 end
Tercio@11 462
Tercio@11 463 else
Tercio@11 464 local color = DF.alias_text_colors [_arg1]
Tercio@11 465 if (color) then
Tercio@11 466 _arg1, _arg2, _arg3, _arg4 = _unpack (color)
Tercio@11 467 else
Tercio@11 468 _arg1, _arg2, _arg3, _arg4 = _unpack (DF.alias_text_colors.none)
Tercio@11 469 end
Tercio@11 470 end
Tercio@11 471 end
Tercio@11 472
Tercio@11 473 if (not _arg1) then
Tercio@11 474 _arg1 = 1
Tercio@11 475 end
Tercio@11 476 if (not _arg2) then
Tercio@11 477 _arg2 = 1
Tercio@11 478 end
Tercio@11 479 if (not _arg3) then
Tercio@11 480 _arg3 = 1
Tercio@11 481 end
Tercio@11 482 if (not _arg4) then
Tercio@11 483 _arg4 = 1
Tercio@11 484 end
Tercio@11 485
Tercio@11 486 return _arg1, _arg2, _arg3, _arg4
Tercio@11 487 end
Tercio@11 488
Tercio@11 489 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 490 --> menus
Tercio@11 491
Tercio@11 492 function DF:BuildMenu (parent, menu, x_offset, y_offset, height)
Tercio@11 493
Tercio@11 494 local cur_x = x_offset
Tercio@11 495 local cur_y = y_offset
Tercio@11 496 local max_x = 0
Tercio@11 497
Tercio@11 498 height = abs ((height or parent:GetHeight()) - abs (y_offset) + 20)
Tercio@11 499 height = height*-1
Tercio@11 500
Tercio@11 501 for index, widget_table in ipairs (menu) do
Tercio@11 502
Tercio@11 503 if (widget_table.type == "select" or widget_table.type == "dropdown") then
Tercio@11 504 local dropdown = self:NewDropDown (parent, nil, "$parentWidget" .. index, nil, 140, 18, widget_table.values, widget_table.get())
Tercio@11 505 dropdown.tooltip = widget_table.desc
Tercio@11 506 local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12)
Tercio@11 507 dropdown:SetPoint ("left", label, "right", 2)
Tercio@11 508 label:SetPoint (cur_x, cur_y)
Tercio@11 509
Tercio@11 510 local size = label.widget:GetStringWidth() + 140 + 4
Tercio@11 511 if (size > max_x) then
Tercio@11 512 max_x = size
Tercio@11 513 end
Tercio@11 514
Tercio@11 515 elseif (widget_table.type == "toggle" or widget_table.type == "switch") then
Tercio@11 516 local switch = self:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get())
Tercio@11 517 switch.tooltip = widget_table.desc
Tercio@11 518 switch.OnSwitch = widget_table.set
Tercio@11 519
Tercio@11 520 local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12)
Tercio@11 521 switch:SetPoint ("left", label, "right", 2)
Tercio@11 522 label:SetPoint (cur_x, cur_y)
Tercio@11 523
Tercio@11 524 local size = label.widget:GetStringWidth() + 60 + 4
Tercio@11 525 if (size > max_x) then
Tercio@11 526 max_x = size
Tercio@11 527 end
Tercio@11 528
Tercio@11 529 elseif (widget_table.type == "range" or widget_table.type == "slider") then
Tercio@11 530 local is_decimanls = widget_table.usedecimals
Tercio@11 531 local slider = self:NewSlider (parent, nil, "$parentWidget" .. index, nil, 140, 20, widget_table.min, widget_table.max, widget_table.step, widget_table.get(), is_decimanls)
Tercio@11 532 slider.tooltip = widget_table.desc
Tercio@11 533 slider:SetHook ("OnValueChange", widget_table.set)
Tercio@11 534
Tercio@11 535 local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12)
Tercio@11 536 slider:SetPoint ("left", label, "right", 2)
Tercio@11 537 label:SetPoint (cur_x, cur_y)
Tercio@11 538
Tercio@11 539 local size = label.widget:GetStringWidth() + 140 + 6
Tercio@11 540 if (size > max_x) then
Tercio@11 541 max_x = size
Tercio@11 542 end
Tercio@11 543
Tercio@11 544 elseif (widget_table.type == "color" or widget_table.type == "color") then
Tercio@11 545 local colorpick = self:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set)
Tercio@11 546 colorpick.tooltip = widget_table.desc
Tercio@11 547
Tercio@11 548 local default_value, g, b, a = widget_table.get()
Tercio@11 549 if (type (default_value) == "table") then
Tercio@11 550 colorpick:SetColor (unpack (default_value))
Tercio@11 551 else
Tercio@11 552 colorpick:SetColor (default_value, g, b, a)
Tercio@11 553 end
Tercio@11 554
Tercio@11 555 local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12)
Tercio@11 556 colorpick:SetPoint ("left", label, "right", 2)
Tercio@11 557 label:SetPoint (cur_x, cur_y)
Tercio@11 558
Tercio@11 559 local size = label.widget:GetStringWidth() + 60 + 4
Tercio@11 560 if (size > max_x) then
Tercio@11 561 max_x = size
Tercio@11 562 end
Tercio@11 563
Tercio@11 564 elseif (widget_table.type == "execute" or widget_table.type == "button") then
Tercio@11 565
Tercio@11 566 local button = self:NewButton (parent, nil, "$parentWidget", nil, 120, 18, widget_table.func, widget_table.param1, widget_table.param2, nil, widget_table.name)
Tercio@11 567 button:InstallCustomTexture()
Tercio@11 568 button:SetPoint (cur_x, cur_y)
Tercio@11 569 button.tooltip = widget_table.desc
Tercio@11 570
Tercio@11 571 local size = button:GetWidth() + 4
Tercio@11 572 if (size > max_x) then
Tercio@11 573 max_x = size
Tercio@11 574 end
Tercio@11 575
Tercio@11 576 end
Tercio@11 577
Tercio@11 578 if (widget_table.spacement) then
Tercio@11 579 cur_y = cur_y - 30
Tercio@11 580 else
Tercio@11 581 cur_y = cur_y - 20
Tercio@11 582 end
Tercio@11 583
Tercio@11 584 if (cur_y < height) then
Tercio@11 585 cur_y = y_offset
Tercio@11 586 cur_x = cur_x + max_x + 30
Tercio@11 587
Tercio@11 588 max_x = 0
Tercio@11 589 end
Tercio@11 590
Tercio@11 591 end
Tercio@11 592
Tercio@11 593 end
Tercio@11 594
Tercio@11 595 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 596 --> tutorials
Tercio@11 597
Tercio@11 598 function DF:ShowTutorialAlertFrame (maintext, desctext, clickfunc)
Tercio@11 599
Tercio@11 600 local TutorialAlertFrame = _G.DetailsFrameworkTutorialAlertFrame
Tercio@11 601
Tercio@11 602 if (not TutorialAlertFrame) then
Tercio@11 603
Tercio@11 604 TutorialAlertFrame = CreateFrame ("ScrollFrame", "DetailsFrameworkTutorialAlertFrame", UIParent, "DetailsFrameworkTutorialAlertFrameTemplate")
Tercio@11 605 TutorialAlertFrame.isFirst = true
Tercio@11 606 TutorialAlertFrame:SetPoint ("left", UIParent, "left", -20, 100)
Tercio@11 607
Tercio@11 608 TutorialAlertFrame:SetWidth (290)
Tercio@11 609 TutorialAlertFrame.ScrollChild:SetWidth (256)
Tercio@11 610
Tercio@11 611 local scrollname = TutorialAlertFrame.ScrollChild:GetName()
Tercio@11 612 _G [scrollname .. "BorderTopLeft"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 613 _G [scrollname .. "BorderTopRight"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 614 _G [scrollname .. "BorderBotLeft"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 615 _G [scrollname .. "BorderBotRight"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 616 _G [scrollname .. "BorderLeft"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 617 _G [scrollname .. "BorderRight"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 618 _G [scrollname .. "BorderBottom"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 619 _G [scrollname .. "BorderTop"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 620
Tercio@11 621 local iconbg = _G [scrollname .. "QuestIconBg"]
Tercio@11 622 iconbg:SetTexture ([[Interface\MainMenuBar\UI-MainMenuBar-EndCap-Human]])
Tercio@11 623 iconbg:SetTexCoord (0, 1, 0, 1)
Tercio@11 624 iconbg:SetSize (100, 100)
Tercio@11 625 iconbg:ClearAllPoints()
Tercio@11 626 iconbg:SetPoint ("bottomleft", TutorialAlertFrame.ScrollChild, "bottomleft")
Tercio@11 627
Tercio@11 628 _G [scrollname .. "Exclamation"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 629 _G [scrollname .. "QuestionMark"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 630
Tercio@11 631 _G [scrollname .. "TopText"]:SetText ("Details!") --string
Tercio@11 632 _G [scrollname .. "QuestName"]:SetText ("") --string
Tercio@11 633 _G [scrollname .. "BottomText"]:SetText ("") --string
Tercio@11 634
Tercio@11 635 TutorialAlertFrame.ScrollChild.IconShine:SetTexture ([[Interface\MainMenuBar\UI-MainMenuBar-EndCap-Human]])
Tercio@11 636
Tercio@11 637 TutorialAlertFrame:SetScript ("OnMouseUp", function (self)
Tercio@11 638 if (self.clickfunc and type (self.clickfunc) == "function") then
Tercio@11 639 self.clickfunc()
Tercio@11 640 end
Tercio@11 641 self:Hide()
Tercio@11 642 end)
Tercio@11 643 TutorialAlertFrame:Hide()
Tercio@11 644 end
Tercio@11 645
Tercio@11 646 if (type (maintext) == "string") then
Tercio@11 647 TutorialAlertFrame.ScrollChild.QuestName:SetText (maintext)
Tercio@11 648 else
Tercio@11 649 TutorialAlertFrame.ScrollChild.QuestName:SetText ("")
Tercio@11 650 end
Tercio@11 651
Tercio@11 652 if (type (desctext) == "string") then
Tercio@11 653 TutorialAlertFrame.ScrollChild.BottomText:SetText (desctext)
Tercio@11 654 else
Tercio@11 655 TutorialAlertFrame.ScrollChild.BottomText:SetText ("")
Tercio@11 656 end
Tercio@11 657
Tercio@11 658 TutorialAlertFrame.clickfunc = clickfunc
Tercio@11 659 TutorialAlertFrame:Show()
Tercio@11 660 DetailsTutorialAlertFrame_SlideInFrame (TutorialAlertFrame, "AUTOQUEST")
Tercio@11 661 end
Tercio@11 662
Tercio@11 663 function DF:CreateOptionsFrame (name, title, template)
Tercio@11 664
Tercio@11 665 template = template or 1
Tercio@11 666
Tercio@11 667 if (template == 2) then
Tercio@11 668 local options_frame = CreateFrame ("frame", name, UIParent, "ButtonFrameTemplate")
Tercio@11 669 tinsert (UISpecialFrames, name)
Tercio@11 670 options_frame:SetSize (500, 200)
Tercio@11 671
Tercio@11 672 options_frame:SetScript ("OnMouseDown", function(self, button)
Tercio@11 673 if (button == "RightButton") then
Tercio@11 674 if (self.moving) then
Tercio@11 675 self.moving = false
Tercio@11 676 self:StopMovingOrSizing()
Tercio@11 677 end
Tercio@11 678 return options_frame:Hide()
Tercio@11 679 elseif (button == "LeftButton" and not self.moving) then
Tercio@11 680 self.moving = true
Tercio@11 681 self:StartMoving()
Tercio@11 682 end
Tercio@11 683 end)
Tercio@11 684 options_frame:SetScript ("OnMouseUp", function(self)
Tercio@11 685 if (self.moving) then
Tercio@11 686 self.moving = false
Tercio@11 687 self:StopMovingOrSizing()
Tercio@11 688 end
Tercio@11 689 end)
Tercio@11 690
Tercio@11 691 options_frame:SetMovable (true)
Tercio@11 692 options_frame:EnableMouse (true)
Tercio@11 693 options_frame:SetFrameStrata ("DIALOG")
Tercio@11 694 options_frame:SetToplevel (true)
Tercio@11 695
Tercio@11 696 options_frame:Hide()
Tercio@11 697
Tercio@11 698 options_frame:SetPoint ("center", UIParent, "center")
Tercio@11 699 options_frame.TitleText:SetText (title)
Tercio@11 700 options_frame.portrait:SetTexture ([[Interface\CHARACTERFRAME\TEMPORARYPORTRAIT-FEMALE-BLOODELF]])
Tercio@11 701
Tercio@11 702 return options_frame
Tercio@11 703
Tercio@11 704 elseif (template == 1) then
Tercio@11 705
Tercio@11 706 local options_frame = CreateFrame ("frame", name, UIParent)
Tercio@11 707 tinsert (UISpecialFrames, name)
Tercio@11 708 options_frame:SetSize (500, 200)
Tercio@11 709
Tercio@11 710 options_frame:SetScript ("OnMouseDown", function(self, button)
Tercio@11 711 if (button == "RightButton") then
Tercio@11 712 if (self.moving) then
Tercio@11 713 self.moving = false
Tercio@11 714 self:StopMovingOrSizing()
Tercio@11 715 end
Tercio@11 716 return options_frame:Hide()
Tercio@11 717 elseif (button == "LeftButton" and not self.moving) then
Tercio@11 718 self.moving = true
Tercio@11 719 self:StartMoving()
Tercio@11 720 end
Tercio@11 721 end)
Tercio@11 722 options_frame:SetScript ("OnMouseUp", function(self)
Tercio@11 723 if (self.moving) then
Tercio@11 724 self.moving = false
Tercio@11 725 self:StopMovingOrSizing()
Tercio@11 726 end
Tercio@11 727 end)
Tercio@11 728
Tercio@11 729 options_frame:SetMovable (true)
Tercio@11 730 options_frame:EnableMouse (true)
Tercio@11 731 options_frame:SetFrameStrata ("DIALOG")
Tercio@11 732 options_frame:SetToplevel (true)
Tercio@11 733
Tercio@11 734 options_frame:Hide()
Tercio@11 735
Tercio@11 736 options_frame:SetPoint ("center", UIParent, "center")
Tercio@11 737
Tercio@11 738 options_frame:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
Tercio@11 739 edgeFile = [[Interface\AddOns\Details\images\border_2]], edgeSize = 32,
Tercio@11 740 insets = {left = 1, right = 1, top = 1, bottom = 1}})
Tercio@11 741 options_frame:SetBackdropColor (0, 0, 0, .7)
Tercio@11 742
Tercio@11 743 local texturetitle = options_frame:CreateTexture (nil, "artwork")
Tercio@11 744 texturetitle:SetTexture ([[Interface\CURSOR\Interact]])
Tercio@11 745 texturetitle:SetTexCoord (0, 1, 0, 1)
Tercio@11 746 texturetitle:SetVertexColor (1, 1, 1, 1)
Tercio@11 747 texturetitle:SetPoint ("topleft", options_frame, "topleft", 2, -3)
Tercio@11 748 texturetitle:SetWidth (36)
Tercio@11 749 texturetitle:SetHeight (36)
Tercio@11 750
Tercio@11 751 local title = DF:NewLabel (options_frame, nil, "$parentTitle", nil, title, nil, 20, "yellow")
Tercio@11 752 title:SetPoint ("left", texturetitle, "right", 2, -1)
Tercio@11 753 DF:SetFontOutline (title, true)
Tercio@11 754
Tercio@11 755 local c = CreateFrame ("Button", nil, options_frame, "UIPanelCloseButton")
Tercio@11 756 c:SetWidth (32)
Tercio@11 757 c:SetHeight (32)
Tercio@11 758 c:SetPoint ("TOPRIGHT", options_frame, "TOPRIGHT", -3, -3)
Tercio@11 759 c:SetFrameLevel (options_frame:GetFrameLevel()+1)
Tercio@11 760
Tercio@11 761 return options_frame
Tercio@11 762 end
Tercio@11 763 end