annotate Libs/DF/fw.lua @ 26:e16b1fc13935

- framework update.
author Tercio
date Fri, 16 Oct 2015 14:46:27 -0300
parents 6bb668a41455
children 7523376ecaa3
rev   line source
Tercio@11 1
Tercio@26 2 local dversion = 12
Tercio@25 3 local major, minor = "DetailsFramework-1.0", dversion
Tercio@11 4 local DF, oldminor = LibStub:NewLibrary (major, minor)
Tercio@11 5
Tercio@18 6 if (not DF) then
Tercio@20 7 DetailsFrameworkCanLoad = false
Tercio@11 8 return
Tercio@11 9 end
Tercio@11 10
Tercio@20 11 DetailsFrameworkCanLoad = true
Tercio@25 12 local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0")
Tercio@18 13
Tercio@11 14 local _type = type
Tercio@11 15 local _unpack = unpack
Tercio@11 16 local _
Tercio@11 17 local upper = string.upper
Tercio@11 18
Tercio@11 19 DF.LabelNameCounter = 1
Tercio@11 20 DF.PictureNameCounter = 1
Tercio@11 21 DF.BarNameCounter = 1
Tercio@11 22 DF.DropDownCounter = 1
Tercio@11 23 DF.PanelCounter = 1
Tercio@11 24 DF.ButtonCounter = 1
Tercio@11 25 DF.SliderCounter = 1
Tercio@11 26 DF.SplitBarCounter = 1
Tercio@11 27
Tercio@25 28 DF.FrameWorkVersion = tostring (dversion)
Tercio@25 29 function DF:PrintVersion()
Tercio@25 30 print ("Details! Framework Version:", DF.FrameWorkVersion)
Tercio@25 31 end
Tercio@25 32
Tercio@22 33 LibStub:GetLibrary("AceTimer-3.0"):Embed (DF)
Tercio@22 34
Tercio@11 35 do
Tercio@11 36 local path = string.match (debugstack (1, 1, 0), "AddOns\\(.+)fw.lua")
Tercio@11 37 if (path) then
Tercio@11 38 DF.folder = "Interface\\AddOns\\" .. path
Tercio@11 39 else
Tercio@11 40 DF.folder = ""
Tercio@11 41 end
Tercio@11 42 end
Tercio@11 43
Tercio@11 44 DF.debug = false
Tercio@11 45
Tercio@11 46 _G ["DetailsFramework"] = DF
Tercio@11 47
Tercio@11 48 DF.embeds = DF.embeds or {}
Tercio@11 49 local embed_functions = {
Tercio@20 50 "RemoveRealName",
Tercio@20 51 "table",
Tercio@20 52 "BuildDropDownFontList",
Tercio@11 53 "SetFontSize",
Tercio@11 54 "SetFontFace",
Tercio@11 55 "SetFontColor",
Tercio@11 56 "GetFontSize",
Tercio@11 57 "GetFontFace",
Tercio@17 58 "SetFontOutline",
Tercio@11 59 "trim",
Tercio@11 60 "Msg",
Tercio@11 61 "CreateFlashAnimation",
Tercio@11 62 "Fade",
Tercio@11 63 "NewColor",
Tercio@11 64 "IsHtmlColor",
Tercio@11 65 "ParseColors",
Tercio@11 66 "BuildMenu",
Tercio@11 67 "ShowTutorialAlertFrame",
Tercio@11 68 "GetNpcIdFromGuid",
Tercio@11 69 "ShowFeedbackPanel",
Tercio@20 70 "SetAsOptionsPanel",
Tercio@11 71
Tercio@11 72 "CreateDropDown",
Tercio@11 73 "CreateButton",
Tercio@11 74 "CreateColorPickButton",
Tercio@11 75 "CreateLabel",
Tercio@11 76 "CreateBar",
Tercio@11 77 "CreatePanel",
Tercio@11 78 "CreateFillPanel",
Tercio@11 79 "ColorPick",
Tercio@11 80 "IconPick",
Tercio@11 81 "CreateSimplePanel",
Tercio@11 82 "CreateChartPanel",
Tercio@11 83 "CreateImage",
Tercio@11 84 "CreateScrollBar",
Tercio@11 85 "CreateSwitch",
Tercio@11 86 "CreateSlider",
Tercio@11 87 "CreateSplitBar",
Tercio@11 88 "CreateTextEntry",
Tercio@11 89 "Create1PxPanel",
Tercio@11 90 "CreateFeedbackButton",
Tercio@20 91 "CreateOptionsFrame",
Tercio@22 92 "NewSpecialLuaEditorEntry",
Tercio@20 93 "ShowPromptPanel",
Tercio@22 94 "ShowTextPromptPanel",
Tercio@11 95 "www_icons",
Tercio@22 96 "GetTemplate",
Tercio@22 97 "GetFrameworkFolder",
Tercio@11 98 }
Tercio@11 99
Tercio@20 100 DF.table = {}
Tercio@20 101
Tercio@22 102 function DF:GetFrameworkFolder()
Tercio@22 103 return DF.folder
Tercio@22 104 end
Tercio@22 105
Tercio@26 106 function DF:FadeFrame (frame, t)
Tercio@26 107 if (t == 0) then
Tercio@26 108 frame.hidden = false
Tercio@26 109 frame.faded = false
Tercio@26 110 frame.fading_out = false
Tercio@26 111 frame.fading_in = false
Tercio@26 112 frame:Show()
Tercio@26 113 frame:SetAlpha (1)
Tercio@26 114
Tercio@26 115 elseif (t == 1) then
Tercio@26 116 frame.hidden = true
Tercio@26 117 frame.faded = true
Tercio@26 118 frame.fading_out = false
Tercio@26 119 frame.fading_in = false
Tercio@26 120 frame:SetAlpha (0)
Tercio@26 121 frame:Hide()
Tercio@26 122 end
Tercio@26 123 end
Tercio@26 124
Tercio@20 125 function DF.table.reverse (t)
Tercio@20 126 local new = {}
Tercio@20 127 local index = 1
Tercio@20 128 for i = #t, 1, -1 do
Tercio@20 129 new [index] = t[i]
Tercio@20 130 index = index + 1
Tercio@20 131 end
Tercio@20 132 return new
Tercio@20 133 end
Tercio@20 134
Tercio@20 135 --> copy from table2 to table1 overwriting values
Tercio@20 136 function DF.table.copy (t1, t2)
Tercio@20 137 for key, value in pairs (t2) do
Tercio@20 138 if (type (value) == "table") then
Tercio@20 139 t1 [key] = t1 [key] or {}
Tercio@20 140 DF.table.copy (t1 [key], t2 [key])
Tercio@20 141 else
Tercio@20 142 t1 [key] = value
Tercio@20 143 end
Tercio@20 144 end
Tercio@20 145 return t1
Tercio@20 146 end
Tercio@20 147
Tercio@20 148 --> copy values that does exist on table2 but not on table1
Tercio@20 149 function DF.table.deploy (t1, t2)
Tercio@20 150 for key, value in pairs (t2) do
Tercio@20 151 if (type (value) == "table") then
Tercio@20 152 t1 [key] = t1 [key] or {}
Tercio@20 153 DF.table.deploy (t1 [key], t2 [key])
Tercio@22 154 elseif (t1 [key] == nil) then
Tercio@20 155 t1 [key] = value
Tercio@20 156 end
Tercio@20 157 end
Tercio@20 158 end
Tercio@20 159
Tercio@20 160 function DF.table.dump (t, s, deep)
Tercio@20 161 s = s or ""
Tercio@20 162 deep = deep or 0
Tercio@20 163 local space = ""
Tercio@20 164 for i = 1, deep do
Tercio@20 165 space = space .. " "
Tercio@20 166 end
Tercio@20 167 for key, value in pairs (t) do
Tercio@20 168 local tpe = _type (value)
Tercio@20 169 if (type (key) ~= "string") then
Tercio@20 170 key = "unknown?"
Tercio@20 171 end
Tercio@20 172 if (tpe == "table") then
Tercio@20 173 s = s .. space .. "[" .. key .. "] = |cFFa9ffa9table {|r\n"
Tercio@20 174 s = s .. DF.table.dump (value, nil, deep+1)
Tercio@20 175 s = s .. space .. "|cFFa9ffa9}|r\n"
Tercio@20 176 elseif (tpe == "string") then
Tercio@20 177 s = s .. space .. "[" .. key .. "] = '|cFFfff1c1" .. value .. "|r'\n"
Tercio@20 178 elseif (tpe == "number") then
Tercio@20 179 s = s .. space .. "[" .. key .. "] = |cFFffc1f4" .. value .. "|r\n"
Tercio@20 180 elseif (tpe == "function") then
Tercio@20 181 s = s .. space .. "[" .. key .. "] = function()\n"
Tercio@20 182 elseif (tpe == "boolean") then
Tercio@20 183 s = s .. space .. "[" .. key .. "] = |cFF99d0ff" .. (value and "true" or "false") .. "|r\n"
Tercio@20 184 end
Tercio@20 185 end
Tercio@20 186 return s
Tercio@20 187 end
Tercio@20 188
Tercio@11 189 DF.www_icons = {
Tercio@11 190 texture = "feedback_sites",
Tercio@11 191 wowi = {0, 0.7890625, 0, 37/128},
Tercio@11 192 curse = {0, 0.7890625, 38/123, 79/128},
Tercio@11 193 mmoc = {0, 0.7890625, 80/123, 123/128},
Tercio@11 194 }
Tercio@11 195
Tercio@24 196 function DF:IntegerToTimer (value)
Tercio@24 197 return "" .. floor (value/60) .. ":" .. format ("%02.f", value%60)
Tercio@24 198 end
Tercio@24 199
Tercio@11 200 function DF:Embed (target)
Tercio@11 201 for k, v in pairs (embed_functions) do
Tercio@11 202 target[v] = self[v]
Tercio@11 203 end
Tercio@11 204 self.embeds [target] = true
Tercio@11 205 return target
Tercio@11 206 end
Tercio@11 207
Tercio@20 208 function DF:RemoveRealName (name)
Tercio@20 209 return name:gsub (("%-.*"), "")
Tercio@20 210 end
Tercio@20 211
Tercio@11 212 function DF:SetFontSize (fontString, ...)
Tercio@11 213 local fonte, _, flags = fontString:GetFont()
Tercio@11 214 fontString:SetFont (fonte, max (...), flags)
Tercio@11 215 end
Tercio@11 216 function DF:SetFontFace (fontString, fontface)
Tercio@25 217 local font = SharedMedia:Fetch ("font", fontface, true)
Tercio@25 218 if (font) then
Tercio@25 219 fontface = font
Tercio@25 220 end
Tercio@25 221
Tercio@11 222 local _, size, flags = fontString:GetFont()
Tercio@11 223 fontString:SetFont (fontface, size, flags)
Tercio@11 224 end
Tercio@11 225 function DF:SetFontColor (fontString, r, g, b, a)
Tercio@11 226 r, g, b, a = DF:ParseColors (r, g, b, a)
Tercio@11 227 fontString:SetTextColor (r, g, b, a)
Tercio@11 228 end
Tercio@11 229
Tercio@11 230 function DF:GetFontSize (fontString)
Tercio@11 231 local _, size = fontString:GetFont()
Tercio@11 232 return size
Tercio@11 233 end
Tercio@11 234 function DF:GetFontFace (fontString)
Tercio@11 235 local fontface = fontString:GetFont()
Tercio@11 236 return fontface
Tercio@11 237 end
Tercio@11 238
Tercio@11 239 function DF:SetFontOutline (fontString, outline)
Tercio@11 240 local fonte, size = fontString:GetFont()
Tercio@11 241 if (outline) then
Tercio@11 242 if (_type (outline) == "boolean" and outline) then
Tercio@11 243 outline = "OUTLINE"
Tercio@11 244 elseif (outline == 1) then
Tercio@11 245 outline = "OUTLINE"
Tercio@11 246 elseif (outline == 2) then
Tercio@11 247 outline = "THICKOUTLINE"
Tercio@11 248 end
Tercio@11 249 end
Tercio@11 250
Tercio@11 251 fontString:SetFont (fonte, size, outline)
Tercio@11 252 end
Tercio@11 253
Tercio@11 254 function DF:trim (s)
Tercio@11 255 local from = s:match"^%s*()"
Tercio@11 256 return from > #s and "" or s:match(".*%S", from)
Tercio@11 257 end
Tercio@11 258
Tercio@11 259 function DF:Msg (msg)
Tercio@11 260 print ("|cFFFFFFAA" .. self.__name .. "|r " .. msg)
Tercio@11 261 end
Tercio@11 262
Tercio@11 263 function DF:GetNpcIdFromGuid (guid)
Tercio@11 264 local NpcId = select ( 6, strsplit ( "-", guid ) )
Tercio@11 265 if (NpcId) then
Tercio@11 266 return tonumber ( NpcId )
Tercio@11 267 end
Tercio@11 268 return 0
Tercio@11 269 end
Tercio@11 270
Tercio@11 271 local onFinish = function (self)
Tercio@11 272 if (self.showWhenDone) then
Tercio@11 273 self.frame:SetAlpha (1)
Tercio@11 274 else
Tercio@11 275 self.frame:SetAlpha (0)
Tercio@11 276 self.frame:Hide()
Tercio@11 277 end
Tercio@11 278
Tercio@11 279 if (self.onFinishFunc) then
Tercio@11 280 self:onFinishFunc (self.frame)
Tercio@11 281 end
Tercio@11 282 end
Tercio@11 283
Tercio@11 284 local stop = function (self)
Tercio@11 285 local FlashAnimation = self.FlashAnimation
Tercio@11 286 FlashAnimation:Stop()
Tercio@11 287 end
Tercio@11 288
Tercio@11 289 local flash = function (self, fadeInTime, fadeOutTime, flashDuration, showWhenDone, flashInHoldTime, flashOutHoldTime, loopType)
Tercio@11 290
Tercio@11 291 local FlashAnimation = self.FlashAnimation
Tercio@11 292
Tercio@11 293 local fadeIn = FlashAnimation.fadeIn
Tercio@11 294 local fadeOut = FlashAnimation.fadeOut
Tercio@11 295
Tercio@11 296 fadeIn:Stop()
Tercio@11 297 fadeOut:Stop()
Tercio@11 298
Tercio@11 299 fadeIn:SetDuration (fadeInTime or 1)
Tercio@11 300 fadeIn:SetEndDelay (flashInHoldTime or 0)
Tercio@11 301
Tercio@11 302 fadeOut:SetDuration (fadeOutTime or 1)
Tercio@11 303 fadeOut:SetEndDelay (flashOutHoldTime or 0)
Tercio@11 304
Tercio@11 305 FlashAnimation.duration = flashDuration
Tercio@11 306 FlashAnimation.loopTime = FlashAnimation:GetDuration()
Tercio@11 307 FlashAnimation.finishAt = GetTime() + flashDuration
Tercio@11 308 FlashAnimation.showWhenDone = showWhenDone
Tercio@11 309
Tercio@11 310 FlashAnimation:SetLooping (loopType or "REPEAT")
Tercio@11 311
Tercio@11 312 self:Show()
Tercio@11 313 self:SetAlpha (0)
Tercio@11 314 FlashAnimation:Play()
Tercio@11 315 end
Tercio@11 316
Tercio@11 317 function DF:CreateFlashAnimation (frame, onFinishFunc, onLoopFunc)
Tercio@11 318 local FlashAnimation = frame:CreateAnimationGroup()
Tercio@11 319
Tercio@11 320 FlashAnimation.fadeOut = FlashAnimation:CreateAnimation ("Alpha") --> fade out anime
Tercio@11 321 FlashAnimation.fadeOut:SetOrder (1)
Tercio@11 322 FlashAnimation.fadeOut:SetChange (1)
Tercio@11 323
Tercio@11 324 FlashAnimation.fadeIn = FlashAnimation:CreateAnimation ("Alpha") --> fade in anime
Tercio@11 325 FlashAnimation.fadeIn:SetOrder (2)
Tercio@11 326 FlashAnimation.fadeIn:SetChange (-1)
Tercio@11 327
Tercio@11 328 frame.FlashAnimation = FlashAnimation
Tercio@11 329 FlashAnimation.frame = frame
Tercio@11 330 FlashAnimation.onFinishFunc = onFinishFunc
Tercio@11 331
Tercio@11 332 FlashAnimation:SetScript ("OnLoop", onLoopFunc)
Tercio@11 333 FlashAnimation:SetScript ("OnFinished", onFinish)
Tercio@11 334
Tercio@11 335 frame.Flash = flash
Tercio@11 336 frame.Stop = stop
Tercio@11 337 end
Tercio@11 338
Tercio@11 339 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 340 --> points
Tercio@11 341
Tercio@11 342 function DF:CheckPoints (v1, v2, v3, v4, v5, object)
Tercio@11 343
Tercio@11 344 if (not v1 and not v2) then
Tercio@11 345 return "topleft", object.widget:GetParent(), "topleft", 0, 0
Tercio@11 346 end
Tercio@11 347
Tercio@11 348 if (_type (v1) == "string") then
Tercio@11 349 local frameGlobal = _G [v1]
Tercio@11 350 if (frameGlobal and frameGlobal.GetObjectType) then
Tercio@11 351 return DF:CheckPoints (frameGlobal, v2, v3, v4, v5, object)
Tercio@11 352 end
Tercio@11 353
Tercio@11 354 elseif (_type (v2) == "string") then
Tercio@11 355 local frameGlobal = _G [v2]
Tercio@11 356 if (frameGlobal and frameGlobal.GetObjectType) then
Tercio@11 357 return DF:CheckPoints (v1, frameGlobal, v3, v4, v5, object)
Tercio@11 358 end
Tercio@11 359 end
Tercio@11 360
Tercio@11 361 if (_type (v1) == "string" and _type (v2) == "table") then --> :setpoint ("left", frame, _, _, _)
Tercio@11 362 if (not v3 or _type (v3) == "number") then --> :setpoint ("left", frame, 10, 10)
Tercio@11 363 v1, v2, v3, v4, v5 = v1, v2, v1, v3, v4
Tercio@11 364 end
Tercio@11 365
Tercio@11 366 elseif (_type (v1) == "string" and _type (v2) == "number") then --> :setpoint ("topleft", x, y)
Tercio@11 367 v1, v2, v3, v4, v5 = v1, object.widget:GetParent(), v1, v2, v3
Tercio@11 368
Tercio@11 369 elseif (_type (v1) == "number") then --> :setpoint (x, y)
Tercio@11 370 v1, v2, v3, v4, v5 = "topleft", object.widget:GetParent(), "topleft", v1, v2
Tercio@11 371
Tercio@11 372 elseif (_type (v1) == "table") then --> :setpoint (frame, x, y)
Tercio@11 373 v1, v2, v3, v4, v5 = "topleft", v1, "topleft", v2, v3
Tercio@11 374
Tercio@11 375 end
Tercio@11 376
Tercio@11 377 if (not v2) then
Tercio@11 378 v2 = object.widget:GetParent()
Tercio@11 379 elseif (v2.dframework) then
Tercio@11 380 v2 = v2.widget
Tercio@11 381 end
Tercio@11 382
Tercio@11 383 return v1 or "topleft", v2, v3 or "topleft", v4 or 0, v5 or 0
Tercio@11 384 end
Tercio@11 385
Tercio@11 386
Tercio@11 387 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 388 --> colors
Tercio@11 389
Tercio@11 390 function DF:NewColor (_colorname, _colortable, _green, _blue, _alpha)
Tercio@11 391 assert (_type (_colorname) == "string", "NewColor: colorname must be a string.")
Tercio@11 392 assert (not DF.alias_text_colors [_colorname], "NewColor: colorname already exists.")
Tercio@11 393
Tercio@11 394 if (_type (_colortable) == "table") then
Tercio@11 395 if (_colortable[1] and _colortable[2] and _colortable[3]) then
Tercio@11 396 _colortable[4] = _colortable[4] or 1
Tercio@11 397 DF.alias_text_colors [_colorname] = _colortable
Tercio@11 398 else
Tercio@11 399 error ("invalid color table.")
Tercio@11 400 end
Tercio@11 401 elseif (_colortable and _green and _blue) then
Tercio@11 402 _alpha = _alpha or 1
Tercio@11 403 DF.alias_text_colors [_colorname] = {_colortable, _green, _blue, _alpha}
Tercio@11 404 else
Tercio@11 405 error ("invalid parameter.")
Tercio@11 406 end
Tercio@11 407
Tercio@11 408 return true
Tercio@11 409 end
Tercio@11 410
Tercio@11 411 function DF:IsHtmlColor (color)
Tercio@11 412 return DF.alias_text_colors [color]
Tercio@11 413 end
Tercio@11 414
Tercio@11 415 local tn = tonumber
Tercio@11 416 function DF:ParseColors (_arg1, _arg2, _arg3, _arg4)
Tercio@11 417 if (_type (_arg1) == "table") then
Tercio@25 418 if (not _arg1[1] and _arg1.r) then
Tercio@25 419 _arg1, _arg2, _arg3, _arg4 = _arg1.r, _arg1.g, _arg1.b, _arg1.a
Tercio@25 420 else
Tercio@25 421 _arg1, _arg2, _arg3, _arg4 = _unpack (_arg1)
Tercio@25 422 end
Tercio@11 423
Tercio@11 424 elseif (_type (_arg1) == "string") then
Tercio@11 425
Tercio@11 426 if (string.find (_arg1, "#")) then
Tercio@11 427 _arg1 = _arg1:gsub ("#","")
Tercio@11 428 if (string.len (_arg1) == 8) then --alpha
Tercio@11 429 _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 430 else
Tercio@11 431 _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 432 end
Tercio@11 433
Tercio@11 434 else
Tercio@11 435 local color = DF.alias_text_colors [_arg1]
Tercio@11 436 if (color) then
Tercio@11 437 _arg1, _arg2, _arg3, _arg4 = _unpack (color)
Tercio@11 438 else
Tercio@11 439 _arg1, _arg2, _arg3, _arg4 = _unpack (DF.alias_text_colors.none)
Tercio@11 440 end
Tercio@11 441 end
Tercio@11 442 end
Tercio@11 443
Tercio@11 444 if (not _arg1) then
Tercio@11 445 _arg1 = 1
Tercio@11 446 end
Tercio@11 447 if (not _arg2) then
Tercio@11 448 _arg2 = 1
Tercio@11 449 end
Tercio@11 450 if (not _arg3) then
Tercio@11 451 _arg3 = 1
Tercio@11 452 end
Tercio@11 453 if (not _arg4) then
Tercio@11 454 _arg4 = 1
Tercio@11 455 end
Tercio@11 456
Tercio@11 457 return _arg1, _arg2, _arg3, _arg4
Tercio@11 458 end
Tercio@11 459
Tercio@11 460 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 461 --> menus
Tercio@11 462
Tercio@22 463 function DF:BuildMenu (parent, menu, x_offset, y_offset, height, use_two_points, text_template, dropdown_template, switch_template, switch_is_box, slider_template, button_template)
Tercio@22 464
Tercio@22 465 if (not parent.widget_list) then
Tercio@22 466 DF:SetAsOptionsPanel (parent)
Tercio@22 467 end
Tercio@11 468
Tercio@11 469 local cur_x = x_offset
Tercio@11 470 local cur_y = y_offset
Tercio@11 471 local max_x = 0
Tercio@11 472
Tercio@11 473 height = abs ((height or parent:GetHeight()) - abs (y_offset) + 20)
Tercio@11 474 height = height*-1
Tercio@11 475
Tercio@11 476 for index, widget_table in ipairs (menu) do
Tercio@11 477
Tercio@20 478 if (widget_table.type == "blank" or widget_table.type == "space") then
Tercio@20 479 -- do nothing
Tercio@20 480
Tercio@20 481 elseif (widget_table.type == "label" or widget_table.type == "text") then
Tercio@22 482 local label = DF:CreateLabel (parent, widget_table.get() or widget_table.text, widget_table.text_template or text_template or widget_table.size, widget_table.color, widget_table.font, nil, "$parentWidget" .. index, "overlay")
Tercio@20 483 label._get = widget_table.get
Tercio@20 484 label.widget_type = "label"
Tercio@20 485 label:SetPoint (cur_x, cur_y)
Tercio@20 486 tinsert (parent.widget_list, label)
Tercio@20 487
Tercio@20 488 elseif (widget_table.type == "select" or widget_table.type == "dropdown") then
Tercio@22 489 local dropdown = DF:NewDropDown (parent, nil, "$parentWidget" .. index, nil, 140, 18, widget_table.values, widget_table.get(), dropdown_template)
Tercio@11 490 dropdown.tooltip = widget_table.desc
Tercio@20 491 dropdown._get = widget_table.get
Tercio@20 492 dropdown.widget_type = "select"
Tercio@22 493 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12)
Tercio@11 494 dropdown:SetPoint ("left", label, "right", 2)
Tercio@11 495 label:SetPoint (cur_x, cur_y)
Tercio@11 496
Tercio@11 497 local size = label.widget:GetStringWidth() + 140 + 4
Tercio@11 498 if (size > max_x) then
Tercio@11 499 max_x = size
Tercio@11 500 end
Tercio@11 501
Tercio@20 502 tinsert (parent.widget_list, dropdown)
Tercio@20 503
Tercio@11 504 elseif (widget_table.type == "toggle" or widget_table.type == "switch") then
Tercio@22 505 local switch = DF:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get(), nil, nil, nil, nil, switch_template)
Tercio@11 506 switch.tooltip = widget_table.desc
Tercio@20 507 switch._get = widget_table.get
Tercio@20 508 switch.widget_type = "toggle"
Tercio@11 509 switch.OnSwitch = widget_table.set
Tercio@11 510
Tercio@22 511 if (switch_is_box) then
Tercio@22 512 switch:SetAsCheckBox()
Tercio@22 513 end
Tercio@22 514
Tercio@22 515 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12)
Tercio@11 516 switch:SetPoint ("left", label, "right", 2)
Tercio@11 517 label:SetPoint (cur_x, cur_y)
Tercio@11 518
Tercio@11 519 local size = label.widget:GetStringWidth() + 60 + 4
Tercio@11 520 if (size > max_x) then
Tercio@11 521 max_x = size
Tercio@11 522 end
Tercio@11 523
Tercio@20 524 tinsert (parent.widget_list, switch)
Tercio@20 525
Tercio@11 526 elseif (widget_table.type == "range" or widget_table.type == "slider") then
Tercio@11 527 local is_decimanls = widget_table.usedecimals
Tercio@22 528 local slider = DF:NewSlider (parent, nil, "$parentWidget" .. index, nil, 140, 20, widget_table.min, widget_table.max, widget_table.step, widget_table.get(), is_decimanls, nil, nil, slider_template)
Tercio@11 529 slider.tooltip = widget_table.desc
Tercio@20 530 slider._get = widget_table.get
Tercio@20 531 slider.widget_type = "range"
Tercio@11 532 slider:SetHook ("OnValueChange", widget_table.set)
Tercio@11 533
Tercio@22 534 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12)
Tercio@11 535 slider:SetPoint ("left", label, "right", 2)
Tercio@11 536 label:SetPoint (cur_x, cur_y)
Tercio@11 537
Tercio@11 538 local size = label.widget:GetStringWidth() + 140 + 6
Tercio@11 539 if (size > max_x) then
Tercio@11 540 max_x = size
Tercio@11 541 end
Tercio@11 542
Tercio@20 543 tinsert (parent.widget_list, slider)
Tercio@20 544
Tercio@11 545 elseif (widget_table.type == "color" or widget_table.type == "color") then
Tercio@22 546 local colorpick = DF:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set, nil, button_template)
Tercio@11 547 colorpick.tooltip = widget_table.desc
Tercio@20 548 colorpick._get = widget_table.get
Tercio@20 549 colorpick.widget_type = "color"
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@22 558 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 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@20 567 tinsert (parent.widget_list, colorpick)
Tercio@20 568
Tercio@11 569 elseif (widget_table.type == "execute" or widget_table.type == "button") then
Tercio@11 570
Tercio@22 571 local button = DF:NewButton (parent, nil, "$parentWidget" .. index, nil, 120, 18, widget_table.func, widget_table.param1, widget_table.param2, nil, widget_table.name, nil, button_template)
Tercio@22 572 if (not button_template) then
Tercio@22 573 button:InstallCustomTexture()
Tercio@22 574 end
Tercio@22 575
Tercio@11 576 button:SetPoint (cur_x, cur_y)
Tercio@11 577 button.tooltip = widget_table.desc
Tercio@20 578 button.widget_type = "execute"
Tercio@11 579
Tercio@11 580 local size = button:GetWidth() + 4
Tercio@11 581 if (size > max_x) then
Tercio@11 582 max_x = size
Tercio@11 583 end
Tercio@11 584
Tercio@20 585 tinsert (parent.widget_list, button)
Tercio@20 586
Tercio@11 587 end
Tercio@11 588
Tercio@11 589 if (widget_table.spacement) then
Tercio@11 590 cur_y = cur_y - 30
Tercio@11 591 else
Tercio@11 592 cur_y = cur_y - 20
Tercio@11 593 end
Tercio@11 594
Tercio@11 595 if (cur_y < height) then
Tercio@11 596 cur_y = y_offset
Tercio@11 597 cur_x = cur_x + max_x + 30
Tercio@11 598
Tercio@11 599 max_x = 0
Tercio@11 600 end
Tercio@11 601
Tercio@11 602 end
Tercio@11 603
Tercio@11 604 end
Tercio@11 605
Tercio@11 606 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 607 --> tutorials
Tercio@11 608
Tercio@11 609 function DF:ShowTutorialAlertFrame (maintext, desctext, clickfunc)
Tercio@11 610
Tercio@11 611 local TutorialAlertFrame = _G.DetailsFrameworkTutorialAlertFrame
Tercio@11 612
Tercio@11 613 if (not TutorialAlertFrame) then
Tercio@11 614
Tercio@11 615 TutorialAlertFrame = CreateFrame ("ScrollFrame", "DetailsFrameworkTutorialAlertFrame", UIParent, "DetailsFrameworkTutorialAlertFrameTemplate")
Tercio@11 616 TutorialAlertFrame.isFirst = true
Tercio@11 617 TutorialAlertFrame:SetPoint ("left", UIParent, "left", -20, 100)
Tercio@11 618
Tercio@11 619 TutorialAlertFrame:SetWidth (290)
Tercio@11 620 TutorialAlertFrame.ScrollChild:SetWidth (256)
Tercio@11 621
Tercio@11 622 local scrollname = TutorialAlertFrame.ScrollChild:GetName()
Tercio@11 623 _G [scrollname .. "BorderTopLeft"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 624 _G [scrollname .. "BorderTopRight"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 625 _G [scrollname .. "BorderBotLeft"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 626 _G [scrollname .. "BorderBotRight"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 627 _G [scrollname .. "BorderLeft"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 628 _G [scrollname .. "BorderRight"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 629 _G [scrollname .. "BorderBottom"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 630 _G [scrollname .. "BorderTop"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 631
Tercio@11 632 local iconbg = _G [scrollname .. "QuestIconBg"]
Tercio@11 633 iconbg:SetTexture ([[Interface\MainMenuBar\UI-MainMenuBar-EndCap-Human]])
Tercio@11 634 iconbg:SetTexCoord (0, 1, 0, 1)
Tercio@11 635 iconbg:SetSize (100, 100)
Tercio@11 636 iconbg:ClearAllPoints()
Tercio@11 637 iconbg:SetPoint ("bottomleft", TutorialAlertFrame.ScrollChild, "bottomleft")
Tercio@11 638
Tercio@11 639 _G [scrollname .. "Exclamation"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 640 _G [scrollname .. "QuestionMark"]:SetVertexColor (1, 0.8, 0, 1)
Tercio@11 641
Tercio@11 642 _G [scrollname .. "TopText"]:SetText ("Details!") --string
Tercio@11 643 _G [scrollname .. "QuestName"]:SetText ("") --string
Tercio@11 644 _G [scrollname .. "BottomText"]:SetText ("") --string
Tercio@11 645
Tercio@11 646 TutorialAlertFrame.ScrollChild.IconShine:SetTexture ([[Interface\MainMenuBar\UI-MainMenuBar-EndCap-Human]])
Tercio@11 647
Tercio@11 648 TutorialAlertFrame:SetScript ("OnMouseUp", function (self)
Tercio@11 649 if (self.clickfunc and type (self.clickfunc) == "function") then
Tercio@11 650 self.clickfunc()
Tercio@11 651 end
Tercio@11 652 self:Hide()
Tercio@11 653 end)
Tercio@11 654 TutorialAlertFrame:Hide()
Tercio@11 655 end
Tercio@11 656
Tercio@11 657 if (type (maintext) == "string") then
Tercio@11 658 TutorialAlertFrame.ScrollChild.QuestName:SetText (maintext)
Tercio@11 659 else
Tercio@11 660 TutorialAlertFrame.ScrollChild.QuestName:SetText ("")
Tercio@11 661 end
Tercio@11 662
Tercio@11 663 if (type (desctext) == "string") then
Tercio@11 664 TutorialAlertFrame.ScrollChild.BottomText:SetText (desctext)
Tercio@11 665 else
Tercio@11 666 TutorialAlertFrame.ScrollChild.BottomText:SetText ("")
Tercio@11 667 end
Tercio@11 668
Tercio@11 669 TutorialAlertFrame.clickfunc = clickfunc
Tercio@11 670 TutorialAlertFrame:Show()
Tercio@11 671 DetailsTutorialAlertFrame_SlideInFrame (TutorialAlertFrame, "AUTOQUEST")
Tercio@11 672 end
Tercio@11 673
Tercio@20 674 local refresh_options = function (self)
Tercio@20 675 for _, widget in ipairs (self.widget_list) do
Tercio@20 676 if (widget._get) then
Tercio@20 677 if (widget.widget_type == "label") then
Tercio@20 678 if (widget._get()) then
Tercio@20 679 widget:SetText (widget._get())
Tercio@20 680 end
Tercio@20 681 elseif (widget.widget_type == "select") then
Tercio@20 682 widget:Select (widget._get())
Tercio@20 683 elseif (widget.widget_type == "toggle" or widget.widget_type == "range") then
Tercio@20 684 widget:SetValue (widget._get())
Tercio@20 685 elseif (widget.widget_type == "color") then
Tercio@20 686 local default_value, g, b, a = widget._get()
Tercio@20 687 if (type (default_value) == "table") then
Tercio@20 688 widget:SetColor (unpack (default_value))
Tercio@20 689 else
Tercio@20 690 widget:SetColor (default_value, g, b, a)
Tercio@20 691 end
Tercio@20 692 end
Tercio@20 693 end
Tercio@20 694 end
Tercio@20 695 end
Tercio@20 696
Tercio@20 697 function DF:SetAsOptionsPanel (frame)
Tercio@20 698 frame.RefreshOptions = refresh_options
Tercio@20 699 frame.widget_list = {}
Tercio@20 700 end
Tercio@20 701
Tercio@11 702 function DF:CreateOptionsFrame (name, title, template)
Tercio@11 703
Tercio@11 704 template = template or 1
Tercio@11 705
Tercio@11 706 if (template == 2) then
Tercio@11 707 local options_frame = CreateFrame ("frame", name, UIParent, "ButtonFrameTemplate")
Tercio@11 708 tinsert (UISpecialFrames, name)
Tercio@11 709 options_frame:SetSize (500, 200)
Tercio@20 710 options_frame.RefreshOptions = refresh_options
Tercio@20 711 options_frame.widget_list = {}
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 options_frame.TitleText:SetText (title)
Tercio@11 741 options_frame.portrait:SetTexture ([[Interface\CHARACTERFRAME\TEMPORARYPORTRAIT-FEMALE-BLOODELF]])
Tercio@11 742
Tercio@11 743 return options_frame
Tercio@11 744
Tercio@11 745 elseif (template == 1) then
Tercio@11 746
Tercio@11 747 local options_frame = CreateFrame ("frame", name, UIParent)
Tercio@11 748 tinsert (UISpecialFrames, name)
Tercio@11 749 options_frame:SetSize (500, 200)
Tercio@20 750 options_frame.RefreshOptions = refresh_options
Tercio@20 751 options_frame.widget_list = {}
Tercio@11 752
Tercio@11 753 options_frame:SetScript ("OnMouseDown", function(self, button)
Tercio@11 754 if (button == "RightButton") then
Tercio@11 755 if (self.moving) then
Tercio@11 756 self.moving = false
Tercio@11 757 self:StopMovingOrSizing()
Tercio@11 758 end
Tercio@11 759 return options_frame:Hide()
Tercio@11 760 elseif (button == "LeftButton" and not self.moving) then
Tercio@11 761 self.moving = true
Tercio@11 762 self:StartMoving()
Tercio@11 763 end
Tercio@11 764 end)
Tercio@11 765 options_frame:SetScript ("OnMouseUp", function(self)
Tercio@11 766 if (self.moving) then
Tercio@11 767 self.moving = false
Tercio@11 768 self:StopMovingOrSizing()
Tercio@11 769 end
Tercio@11 770 end)
Tercio@11 771
Tercio@11 772 options_frame:SetMovable (true)
Tercio@11 773 options_frame:EnableMouse (true)
Tercio@11 774 options_frame:SetFrameStrata ("DIALOG")
Tercio@11 775 options_frame:SetToplevel (true)
Tercio@11 776
Tercio@11 777 options_frame:Hide()
Tercio@11 778
Tercio@11 779 options_frame:SetPoint ("center", UIParent, "center")
Tercio@11 780
Tercio@11 781 options_frame:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
Tercio@18 782 edgeFile = DF.folder .. "border_2", edgeSize = 32,
Tercio@11 783 insets = {left = 1, right = 1, top = 1, bottom = 1}})
Tercio@11 784 options_frame:SetBackdropColor (0, 0, 0, .7)
Tercio@11 785
Tercio@11 786 local texturetitle = options_frame:CreateTexture (nil, "artwork")
Tercio@11 787 texturetitle:SetTexture ([[Interface\CURSOR\Interact]])
Tercio@11 788 texturetitle:SetTexCoord (0, 1, 0, 1)
Tercio@11 789 texturetitle:SetVertexColor (1, 1, 1, 1)
Tercio@11 790 texturetitle:SetPoint ("topleft", options_frame, "topleft", 2, -3)
Tercio@11 791 texturetitle:SetWidth (36)
Tercio@11 792 texturetitle:SetHeight (36)
Tercio@11 793
Tercio@11 794 local title = DF:NewLabel (options_frame, nil, "$parentTitle", nil, title, nil, 20, "yellow")
Tercio@11 795 title:SetPoint ("left", texturetitle, "right", 2, -1)
Tercio@11 796 DF:SetFontOutline (title, true)
Tercio@11 797
Tercio@11 798 local c = CreateFrame ("Button", nil, options_frame, "UIPanelCloseButton")
Tercio@11 799 c:SetWidth (32)
Tercio@11 800 c:SetHeight (32)
Tercio@11 801 c:SetPoint ("TOPRIGHT", options_frame, "TOPRIGHT", -3, -3)
Tercio@11 802 c:SetFrameLevel (options_frame:GetFrameLevel()+1)
Tercio@11 803
Tercio@11 804 return options_frame
Tercio@11 805 end
Tercio@22 806 end
Tercio@22 807
Tercio@22 808 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@22 809 --> templates
Tercio@22 810
Tercio@22 811 DF.font_templates = {}
Tercio@22 812 DF.font_templates ["ORANGE_FONT_TEMPLATE"] = {color = "orange", size = 11, font = "Accidental Presidency"}
Tercio@22 813 DF.font_templates ["OPTIONS_FONT_TEMPLATE"] = {color = "yellow", size = 12, font = "Accidental Presidency"}
Tercio@22 814
Tercio@22 815 DF.dropdown_templates = {}
Tercio@22 816 DF.dropdown_templates ["OPTIONS_DROPDOWN_TEMPLATE"] = {
Tercio@22 817 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
Tercio@22 818 backdropcolor = {1, 1, 1, .5},
Tercio@22 819 backdropbordercolor = {0, 0, 0, 1},
Tercio@22 820 onentercolor = {1, 1, 1, .5},
Tercio@22 821 onenterbordercolor = {1, 1, 1, 1},
Tercio@22 822 }
Tercio@22 823
Tercio@22 824 DF.switch_templates = {}
Tercio@22 825 DF.switch_templates ["OPTIONS_CHECKBOX_TEMPLATE"] = {
Tercio@22 826 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
Tercio@22 827 backdropcolor = {1, 1, 1, .5},
Tercio@22 828 backdropbordercolor = {0, 0, 0, 1},
Tercio@22 829 width = 18,
Tercio@22 830 height = 18,
Tercio@22 831 enabled_backdropcolor = {1, 1, 1, .5},
Tercio@22 832 disabled_backdropcolor = {1, 1, 1, .2},
Tercio@22 833 onenterbordercolor = {1, 1, 1, 1},
Tercio@22 834 }
Tercio@22 835 DF.switch_templates ["OPTIONS_CHECKBOX_BRIGHT_TEMPLATE"] = {
Tercio@22 836 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
Tercio@22 837 backdropcolor = {1, 1, 1, .5},
Tercio@22 838 backdropbordercolor = {0, 0, 0, 1},
Tercio@22 839 width = 18,
Tercio@22 840 height = 18,
Tercio@22 841 enabled_backdropcolor = {1, 1, 1, .5},
Tercio@22 842 disabled_backdropcolor = {1, 1, 1, .5},
Tercio@22 843 onenterbordercolor = {1, 1, 1, 1},
Tercio@22 844 }
Tercio@22 845
Tercio@22 846 DF.button_templates = {}
Tercio@22 847 DF.button_templates ["OPTIONS_BUTTON_TEMPLATE"] = {
Tercio@22 848 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
Tercio@22 849 backdropcolor = {1, 1, 1, .5},
Tercio@22 850 backdropbordercolor = {0, 0, 0, 1},
Tercio@22 851 }
Tercio@22 852
Tercio@22 853 DF.slider_templates = {}
Tercio@22 854 DF.slider_templates ["OPTIONS_SLIDER_TEMPLATE"] = {
Tercio@22 855 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
Tercio@22 856 backdropcolor = {1, 1, 1, .5},
Tercio@22 857 backdropbordercolor = {0, 0, 0, 1},
Tercio@22 858 onentercolor = {1, 1, 1, .5},
Tercio@22 859 onenterbordercolor = {1, 1, 1, 1},
Tercio@22 860 thumbtexture = [[Interface\Tooltips\UI-Tooltip-Background]],
Tercio@22 861 thumbwidth = 16,
Tercio@22 862 thumbheight = 14,
Tercio@22 863 thumbcolor = {0, 0, 0, 0.5},
Tercio@22 864 }
Tercio@22 865
Tercio@22 866 function DF:GetTemplate (type, template_name)
Tercio@22 867 local template_table
Tercio@22 868 if (type == "font") then
Tercio@22 869 template_table = DF.font_templates
Tercio@22 870 elseif (type == "dropdown") then
Tercio@22 871 template_table = DF.dropdown_templates
Tercio@22 872 elseif (type == "button") then
Tercio@22 873 template_table = DF.button_templates
Tercio@22 874 elseif (type == "switch") then
Tercio@22 875 template_table = DF.switch_templates
Tercio@22 876 elseif (type == "slider") then
Tercio@22 877 template_table = DF.slider_templates
Tercio@22 878 end
Tercio@22 879 return template_table [template_name]
Tercio@22 880 end
Tercio@22 881