comparison Libs/DF/panel.lua @ 40:a960d5372b0c

- framework update from v22 to v44.
author Tercio
date Wed, 31 Aug 2016 19:55:14 -0300
parents 7944c081e5b4
children e0a8f43009ea
comparison
equal deleted inserted replaced
39:7944c081e5b4 40:a960d5372b0c
1494 local SimplePanel_frame_backdrop_color = {0, 0, 0, 0.9} 1494 local SimplePanel_frame_backdrop_color = {0, 0, 0, 0.9}
1495 local SimplePanel_frame_backdrop_border_color = {0, 0, 0, 1} 1495 local SimplePanel_frame_backdrop_border_color = {0, 0, 0, 1}
1496 1496
1497 function DF:CreateScaleBar (frame, config) 1497 function DF:CreateScaleBar (frame, config)
1498 local scaleBar = DF:CreateSlider (frame, 120, 14, 0.6, 1.6, 0.1, config.scale, true, "ScaleBar", nil, "Scale:", DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE"), DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) 1498 local scaleBar = DF:CreateSlider (frame, 120, 14, 0.6, 1.6, 0.1, config.scale, true, "ScaleBar", nil, "Scale:", DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE"), DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
1499 scaleBar:SetPoint ("right", frame.Close, "left", -2, 0) 1499 scaleBar:SetPoint ("right", frame.Close, "left", -26, 0)
1500 scaleBar:SetFrameLevel (DF.FRAMELEVEL_OVERLAY) 1500 scaleBar:SetFrameLevel (DF.FRAMELEVEL_OVERLAY)
1501 scaleBar.OnValueChanged = function (_, _, value) 1501 scaleBar.OnValueChanged = function (_, _, value)
1502 config.scale = value 1502 config.scale = value
1503 if (not scaleBar.IsValueChanging) then 1503 if (not scaleBar.IsValueChanging) then
1504 frame:SetScale (config.scale) 1504 frame:SetScale (config.scale)
2521 local line_default_color = {1, 1, 1} 2521 local line_default_color = {1, 1, 1}
2522 local draw_overlay = function (self, this_overlay, overlayData, color) 2522 local draw_overlay = function (self, this_overlay, overlayData, color)
2523 2523
2524 local pixel = self.Graphic:GetWidth() / self.TimeScale 2524 local pixel = self.Graphic:GetWidth() / self.TimeScale
2525 local index = 1 2525 local index = 1
2526 local r, g, b = unpack (color) 2526 local r, g, b = unpack (color or line_default_color)
2527 2527
2528 for i = 1, #overlayData, 2 do 2528 for i = 1, #overlayData, 2 do
2529 local aura_start = overlayData [i] 2529 local aura_start = overlayData [i]
2530 local aura_end = overlayData [i+1] 2530 local aura_end = overlayData [i+1]
2531 2531
3007 spellicon:SetSize (16, 16) 3007 spellicon:SetSize (16, 16)
3008 f.spellicon = spellicon 3008 f.spellicon = spellicon
3009 3009
3010 local timeline = f:CreateFontString (nil, "overlay", "GameFontNormal") 3010 local timeline = f:CreateFontString (nil, "overlay", "GameFontNormal")
3011 timeline:SetPoint ("bottomright", f, "bottomright", -2, 0) 3011 timeline:SetPoint ("bottomright", f, "bottomright", -2, 0)
3012 _detalhes:SetFontSize (timeline, 8) 3012 DF:SetFontSize (timeline, 8)
3013 f.timeline = timeline 3013 f.timeline = timeline
3014 3014
3015 return f 3015 return f
3016 end 3016 end
3017 3017
3048 if (lines [i].value > max_value) then 3048 if (lines [i].value > max_value) then
3049 max_value = lines [i].value 3049 max_value = lines [i].value
3050 end 3050 end
3051 end 3051 end
3052 3052
3053 self.MaxValue = max_value
3054
3053 local o = 1 3055 local o = 1
3054 local lastvalue = self:GetHeight()/2 3056 local lastvalue = self:GetHeight()/2
3057 max_value = math.max (max_value, 0.0000001)
3055 3058
3056 for i = 1, min (amtlines, self._maxlines) do 3059 for i = 1, min (amtlines, self._maxlines) do
3057 3060
3058 local data = lines [i] 3061 local data = lines [i]
3059 3062
3093 3096
3094 f.CreateLine = gframe_create_line 3097 f.CreateLine = gframe_create_line
3095 f.GetLine = gframe_getline 3098 f.GetLine = gframe_getline
3096 f.Reset = gframe_reset 3099 f.Reset = gframe_reset
3097 f.UpdateLines = gframe_update 3100 f.UpdateLines = gframe_update
3101
3102 f.MaxValue = 0
3098 3103
3099 f._lines = {} 3104 f._lines = {}
3100 3105
3101 f._onenter_line = onenter 3106 f._onenter_line = onenter
3102 f._onleave_line = onleave 3107 f._onleave_line = onleave
3328 3333
3329 3334
3330 3335
3331 3336
3332 3337
3333 3338 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3334 3339 -- ~listbox
3335 3340
3336 3341 local simple_list_box_ResetWidgets = function (self)
3337 3342 for _, widget in ipairs (self.widgets) do
3338 3343 widget:Hide()
3339 3344 end
3345 self.nextWidget = 1
3346 end
3347
3348 local simple_list_box_onenter = function (self, capsule)
3349 self:GetParent().options.onenter (self, capsule, capsule.value)
3350 end
3351
3352 local simple_list_box_onleave = function (self, capsule)
3353 self:GetParent().options.onleave (self, capsule, capsule.value)
3354 GameTooltip:Hide()
3355 end
3356
3357 local simple_list_box_GetOrCreateWidget = function (self)
3358 local index = self.nextWidget
3359 local widget = self.widgets [index]
3360 if (not widget) then
3361 widget = DF:CreateButton (self, function()end, self.options.width, self.options.row_height, "", nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"))
3362 widget:SetHook ("OnEnter", simple_list_box_onenter)
3363 widget:SetHook ("OnLeave", simple_list_box_onleave)
3364 widget.textcolor = self.options.textcolor
3365 tinsert (self.widgets, widget)
3366 end
3367 self.nextWidget = self.nextWidget + 1
3368 return widget
3369 end
3370
3371 local simple_list_box_RefreshWidgets = function (self)
3372 self:ResetWidgets()
3373 local amt = 0
3374 for value, _ in pairs (self.list_table) do
3375 local widget = self:GetOrCreateWidget()
3376 widget:SetPoint ("topleft", self, "topleft", 1, -self.options.row_height * (self.nextWidget-2) - 4)
3377 widget:SetPoint ("topright", self, "topright", -1, -self.options.row_height * (self.nextWidget-2) - 4)
3378 widget:SetClickFunction (self.func, value)
3379 widget.value = value
3380
3381 if (self.options.icon) then
3382 if (type (self.options.icon) == "string" or type (self.options.icon) == "number") then
3383 widget:SetIcon (self.options.icon, self.options.row_height, self.options.row_height)
3384 elseif (type (self.options.icon) == "function") then
3385 local icon = self.options.icon (value)
3386 if (icon) then
3387 widget:SetIcon (icon, self.options.row_height, self.options.row_height)
3388 end
3389 end
3390 else
3391 widget:SetIcon ("", self.options.row_height, self.options.row_height)
3392 end
3393
3394 if (self.options.text) then
3395 if (type (self.options.text) == "function") then
3396 local text = self.options.text (value)
3397 if (text) then
3398 widget:SetText (text)
3399 else
3400 widget:SetText ("")
3401 end
3402 else
3403 widget:SetText (self.options.text or "")
3404 end
3405 else
3406 widget:SetText ("")
3407 end
3408
3409 widget.value = value
3410 widget:Show()
3411 amt = amt + 1
3412 end
3413 if (amt == 0) then
3414 self.EmptyLabel:Show()
3415 else
3416 self.EmptyLabel:Hide()
3417 end
3418 end
3419
3420 local backdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1}
3421 local default_options = {
3422 height = 400,
3423 row_height = 16,
3424 width = 230,
3425 icon = false,
3426 text = "",
3427 textcolor = "wheat",
3428 onenter = function (self, capsule)
3429 if (capsule) then
3430 capsule.textcolor = "white"
3431 end
3432 end,
3433 onleave = function (self, capsule)
3434 if (capsule) then
3435 capsule.textcolor = self:GetParent().options.textcolor
3436 end
3437 GameTooltip:Hide()
3438 end,
3439 }
3440
3441 local simple_list_box_SetData = function (self, t)
3442 self.list_table = t
3443 end
3444
3445 function DF:CreateSimpleListBox (parent, name, title, empty_text, list_table, onclick, options)
3446 local f = CreateFrame ("frame", name, parent)
3447
3448 f.ResetWidgets = simple_list_box_ResetWidgets
3449 f.GetOrCreateWidget = simple_list_box_GetOrCreateWidget
3450 f.Refresh = simple_list_box_RefreshWidgets
3451 f.SetData = simple_list_box_SetData
3452 f.nextWidget = 1
3453 f.list_table = list_table
3454 f.func = function (self, button, value)
3455 onclick (value)
3456 f:Refresh()
3457 end
3458 f.widgets = {}
3459 f:SetBackdrop (backdrop)
3460 f:SetBackdropColor (0, 0, 0, 0.3)
3461 f:SetBackdropBorderColor (0, 0, 0, 0.5)
3462 f.options = options or {}
3463 self.table.deploy (f.options, default_options)
3464
3465 f:SetSize (f.options.width + 2, f.options.height)
3466
3467 local name = DF:CreateLabel (f, title, 12, "silver")
3468 name:SetTemplate (DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
3469 name:SetPoint ("bottomleft", f, "topleft", 0, 2)
3470 f.Title = name
3471
3472 local emptyLabel = DF:CreateLabel (f, empty_text, 12, "gray")
3473 emptyLabel:SetAlpha (.6)
3474 emptyLabel:SetSize (f.options.width-10, f.options.height)
3475 emptyLabel:SetPoint ("center", 0, 0)
3476 emptyLabel:Hide()
3477 emptyLabel.align = "center"
3478 f.EmptyLabel = emptyLabel
3479
3480 return f
3481 end
3482
3483
3484 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3485 -- ~scrollbox
3486
3487
3488 -- preciso de uma fauxscroll que seja facil de lidar
3489 -- ele cria scroll aqui, preciso falar a função que cria a linha e a função que atualiza
3490 -- precisa passsar o tamanho em height width quantas barras vai mostrar
3491 -- search box incluso opcionalmente
3492
3493
3494 DF.SortFunctions = {}
3495
3496 local SortMember = ""
3497 local SortByMember = function (t1, t2)
3498 return t1[SortMember] > t2[SortMember]
3499 end
3500 local SortByMemberReverse = function (t1, t2)
3501 return t1[SortMember] < t2[SortMember]
3502 end
3503
3504 DF.SortFunctions.Sort = function (self, t, by, is_reverse)
3505 SortMember = by
3506 if (not is_reverse) then
3507 table.sort (t, SortByMember)
3508 else
3509 table.sort (t, SortByMemberReverse)
3510 end
3511 end
3512
3513
3514 DF.ScrollBoxFunctions = {}
3515
3516 DF.ScrollBoxFunctions.Refresh = function (self)
3517 for _, frame in ipairs (self.Frames) do
3518 frame:Hide()
3519 frame._InUse = nil
3520 end
3521
3522 local offset = 0
3523 if (self.IsFauxScroll) then
3524 FauxScrollFrame_Update (self, #self.data, self.LineAmount, self.LineHeight+1)
3525 offset = FauxScrollFrame_GetOffset (self)
3526 end
3527
3528 local okay, totalLines = pcall (self.refresh_func, self, self.data, offset, #self.Frames)
3529 if (not okay) then
3530 error ("Details! FrameWork: Refresh(): " .. totalLines)
3531 end
3532
3533 for _, frame in ipairs (self.Frames) do
3534 if (not frame._InUse) then
3535 frame:Hide()
3536 else
3537 frame:Show()
3538 end
3539 end
3540
3541 self:Show()
3542
3543 return self.Frames
3544 end
3545
3546 DF.ScrollBoxFunctions.OnVerticalScroll = function (self, offset)
3547 FauxScrollFrame_OnVerticalScroll (self, offset, self.LineHeight, self.Refresh)
3548 return true
3549 end
3550
3551 DF.ScrollBoxFunctions.CreateLine = function (self, func)
3552 local okay, newLine = pcall (func, self, #self.Frames+1)
3553 if (okay) then
3554 tinsert (self.Frames, newLine)
3555 return newLine
3556 else
3557 error ("Details! FrameWork: CreateLine(): " .. newLine)
3558 end
3559 end
3560
3561 DF.ScrollBoxFunctions.GetLine = function (self, line_index)
3562 local line = self.Frames [line_index]
3563 if (line) then
3564 line._InUse = true
3565 end
3566 return line
3567 end
3568
3569 DF.ScrollBoxFunctions.SetData = function (self, data)
3570 self.data = data
3571 end
3572 DF.ScrollBoxFunctions.GetData = function (self)
3573 return self.data
3574 end
3575
3576 function DF:CreateScrollBox (parent, name, refresh_func, data, width, height, line_amount, line_height)
3577 local scroll = CreateFrame ("scrollframe", name, parent, "FauxScrollFrameTemplate")
3578
3579 scroll:SetSize (width, height)
3580 scroll.LineAmount = line_amount
3581 scroll.LineHeight = line_height
3582 scroll.IsFauxScroll = true
3583 scroll.Frames = {}
3584
3585 DF:Mixin (scroll, DF.SortFunctions)
3586 DF:Mixin (scroll, DF.ScrollBoxFunctions)
3587
3588 scroll.refresh_func = refresh_func
3589 scroll.data = data
3590
3591 scroll:SetScript ("OnVerticalScroll", scroll.OnVerticalScroll)
3592
3593 return scroll
3594 end
3595
3596
3597