annotate Libs/DF/fw.lua @ 17:0c160948ac5e

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