annotate Libs/DF/fw.lua @ 18:680465749fc7

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