- merging more updates from the beta version.

This commit is contained in:
Tercio
2016-07-26 19:27:36 -03:00
parent da2d6b9bf4
commit bd0bb3b7d2
9 changed files with 886 additions and 23 deletions
+425
View File
@@ -0,0 +1,425 @@
local DF = _G ["DetailsFramework"]
if (not DF or not DetailsFrameworkCanLoad) then
return
end
local _
local tinsert = tinsert
local GetSpellInfo = GetSpellInfo
local lower = string.lower
local GetSpellBookItemInfo = GetSpellBookItemInfo
local cleanfunction = function() end
do
local metaPrototype = {
WidgetType = "aura_tracker",
SetHook = DF.SetHook,
RunHooksForWidget = DF.RunHooksForWidget,
}
_G [DF.GlobalWidgetControlNames ["aura_tracker"]] = _G [DF.GlobalWidgetControlNames ["aura_tracker"]] or metaPrototype
end
local AuraTrackerMetaFunctions = _G [DF.GlobalWidgetControlNames ["aura_tracker"]]
--create panels
local on_profile_changed = function (self, newdb)
self.db = newdb
self.tracking_method:Select (newdb.aura_tracker.track_method)
--automatic
self.buff_ignored:SetData (newdb.aura_tracker.buff_banned)
self.debuff_ignored:SetData (newdb.aura_tracker.debuff_banned)
self.buff_available:Refresh()
self.buff_ignored:Refresh()
self.debuff_available:Refresh()
self.debuff_ignored:Refresh()
--manual
self.buffs_added:SetData (newdb.aura_tracker.buff)
self.debuffs_added:SetData (newdb.aura_tracker.debuff)
self.buffs_added:Refresh()
self.debuffs_added:Refresh()
--method
if (newdb.aura_tracker.track_method == 0x1) then
self.f_auto:Show()
self.f_manual:Hide()
elseif (newdb.aura_tracker.track_method == 0x2) then
self.f_auto:Hide()
self.f_manual:Show()
end
end
local aura_panel_defaultoptions = {
height = 400,
row_height = 16,
width = 230,
}
function DF:CreateAuraConfigPanel (parent, name, db, method_change_callback, options)
local options_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")
local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
local options_switch_template = DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE")
local options_slider_template = DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE")
local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")
local f = CreateFrame ("frame", name, parent)
f.db = db
f.OnProfileChanged = on_profile_changed
options = options or {}
self.table.deploy (options, aura_panel_defaultoptions)
local f_auto = CreateFrame ("frame", "$parent_Automatic", f)
local f_manual = CreateFrame ("frame", "$parent_Manual", f)
f_auto:SetPoint ("topleft", f, "topleft", 0, -24)
f_manual:SetPoint ("topleft", f, "topleft", 0, -24)
f_auto:SetSize (600, 600)
f_manual:SetSize (600, 600)
f.f_auto = f_auto
f.f_manual = f_manual
local on_select_tracking_option = function (_, _, method)
f.db.aura_tracker.track_method = method
if (method_change_callback) then
method_change_callback (self, method)
end
if (method == 0x1) then
f_auto:Show()
f_manual:Hide()
elseif (method == 0x2) then
f_auto:Hide()
f_manual:Show()
end
end
local tracking_options = function()
return {
{label = "Automatic", value = 0x1, onclick = on_select_tracking_option, desc = "Show all your auras by default, you can exclude those you don't want to show."},
{label = "Manual", value = 0x2, onclick = on_select_tracking_option, desc = "Do not show any aura by default, you need to manually add each aura you want to track."},
}
end
local tracking_method_label = self:CreateLabel (f, "Tracking Aura Method:", 12, "orange")
local tracking_method = self:CreateDropDown (f, tracking_options, f.db.aura_tracker.track_method, 120, 20, "dropdown_tracking_method", _, self:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
tracking_method_label:SetPoint ("topleft", f, "topleft", 10, -10)
tracking_method:SetPoint ("left", tracking_method_label, "right", 2, 0)
tracking_method:SetFrameStrata ("tooltip")
tracking_method.tooltip = "Choose which aura tracking method you want to use."
f.tracking_method = tracking_method
--------automatic
local ALL_BUFFS = {}
local ALL_DEBUFFS = {}
local width, height, row_height = options.width, options.height, options.row_height
local buff_ignored = self:CreateSimpleListBox (f_auto, "$parentBuffIgnored", "Buffs Ignored", "The list is empty, select a spell from the buff list to ignore it.", f.db.aura_tracker.buff_banned,
function (spellid)
f.db.aura_tracker.buff_banned [spellid] = nil;
end,
{
icon = function(spellid) return select (3, GetSpellInfo (spellid)) end,
text = function(spellid) return select (1, GetSpellInfo (spellid)) end,
height = height,
row_height = row_height,
width = width,
onenter = function(self, capsule, value) GameTooltip:SetOwner (self, "ANCHOR_RIGHT"); GameTooltip:SetSpellByID(value); GameTooltip:AddLine (" "); GameTooltip:AddLine ("Click to un-ignore this aura", .2, 1, .2); GameTooltip:Show() end,
})
local buff_available = self:CreateSimpleListBox (f_auto, "$parentBuffAvailable", "Buffs Available", "The list is empty, cast spells to fill it", ALL_BUFFS, function (spellid)
f.db.aura_tracker.buff_banned [spellid] = true; buff_ignored:Refresh()
end,
{
icon = function(spellid) return select (3, GetSpellInfo (spellid)) end,
text = function(spellid) return select (1, GetSpellInfo (spellid)) end,
height = height,
row_height = row_height,
width = width,
onenter = function(self, capsule, value) GameTooltip:SetOwner (self, "ANCHOR_RIGHT"); GameTooltip:SetSpellByID(value); GameTooltip:AddLine (" "); GameTooltip:AddLine ("Click to ignore this aura", .2, 1, .2); GameTooltip:Show() end,
})
local debuff_ignored = self:CreateSimpleListBox (f_auto, "$parentDebuffIgnored", "Debuffs Ignored", "The list is empty, select a spell from the debuff list to ignore it.", f.db.aura_tracker.debuff_banned, function (spellid)
f.db.aura_tracker.debuff_banned [spellid] = nil;
end,
{
icon = function(spellid) return select (3, GetSpellInfo (spellid)) end,
text = function(spellid) return select (1, GetSpellInfo (spellid)) end,
height = height,
row_height = row_height,
width = width,
onenter = function(self, capsule, value) GameTooltip:SetOwner (self, "ANCHOR_RIGHT"); GameTooltip:SetSpellByID(value); GameTooltip:AddLine (" "); GameTooltip:AddLine ("Click to un-ignore this aura", .2, 1, .2); GameTooltip:Show() end,
})
local debuff_available = self:CreateSimpleListBox (f_auto, "$parentDebuffAvailable", "Debuffs Available", "The list is empty, cast spells to fill it", ALL_DEBUFFS, function (spellid)
f.db.aura_tracker.debuff_banned [spellid] = true; debuff_ignored:Refresh()
end, {
icon = function(spellid) return select (3, GetSpellInfo (spellid)) end,
text = function(spellid) return select (1, GetSpellInfo (spellid)) end,
height = height,
row_height = row_height,
width = width,
onenter = function(self, capsule, value) GameTooltip:SetOwner (self, "ANCHOR_RIGHT"); GameTooltip:SetSpellByID(value); GameTooltip:AddLine (" "); GameTooltip:AddLine ("Click to ignore this aura", .2, 1, .2); GameTooltip:Show() end,
})
--como ira preencher ela no inicio e como ficara o lance dos profiles
local y = -30
buff_available:SetPoint ("topleft", f_auto, "topleft", 0, y)
buff_ignored:SetPoint ("topleft", f_auto, "topleft", 6 + width, y)
debuff_available:SetPoint ("topleft", f_auto, "topleft", 12 + (width*2), y)
debuff_ignored:SetPoint ("topleft", f_auto, "topleft", 18 + (width*3), y)
f.buff_available = buff_available
f.buff_ignored = buff_ignored
f.debuff_available = debuff_available
f.debuff_ignored = debuff_ignored
local readCombatLog = CreateFrame ("frame", nil, f_auto)
readCombatLog:SetScript ("OnEvent", function (self, event, time, token, hidding, sourceGUID, sourceName, sourceFlag, sourceFlag2, targetGUID, targetName, targetFlag, targetFlag2, spellid, spellname, spellschool, auraType, amount)
if (auraType == "BUFF" and sourceGUID == readCombatLog.playerGUID) then
if (not ALL_BUFFS [spellid]) then
ALL_BUFFS [spellid] = true
buff_available:Refresh()
end
elseif (auraType == "DEBUFF" and sourceGUID == readCombatLog.playerGUID) then
if (not ALL_DEBUFFS [spellid]) then
ALL_DEBUFFS [spellid] = true
debuff_available:Refresh()
end
end
end)
f_auto:SetScript ("OnShow", function()
for i = 1, BUFF_MAX_DISPLAY do
local name, rank, texture, count, debuffType, duration, expirationTime, caster, _, nameplateShowPersonal, spellId, _, _, _, nameplateShowAll = UnitAura ("player", i, "HELPFUL")
if (name) then
ALL_BUFFS [spellId] = true
end
local name, rank, texture, count, debuffType, duration, expirationTime, caster, _, nameplateShowPersonal, spellId, _, _, _, nameplateShowAll = UnitAura ("player", i, "HARMFUL")
if (name) then
ALL_DEBUFFS [spellId] = true
end
end
buff_available:Refresh()
buff_ignored:Refresh()
debuff_available:Refresh()
debuff_ignored:Refresh()
readCombatLog.playerGUID = UnitGUID ("player")
readCombatLog:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
end)
f_auto:SetScript ("OnHide", function()
readCombatLog:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
end)
--show the frame selecton on the f.db
on_select_tracking_option (_, _, f.db.aura_tracker.track_method)
-------manual
--> build the two aura scrolls for buff and debuff
local scroll_width = width
local scroll_height = height
local scroll_lines = 15
local scroll_line_height = 20
local line_onenter = function (self)
self:SetBackdropColor (.3, .3, .3, 0.4)
local spellid = select (7, GetSpellInfo (self.value))
if (spellid) then
GameTooltip:SetOwner (self, "ANCHOR_RIGHT");
GameTooltip:SetSpellByID (spellid)
GameTooltip:AddLine (" ")
GameTooltip:AddLine ("Click to untrack this aura", .2, 1, .2)
GameTooltip:Show()
end
end
local line_onleave = function (self)
self:SetBackdropColor (0, 0, 0, 0.2)
GameTooltip:Hide()
end
local line_onclick = function (self)
local spell = self.value
local data = self:GetParent():GetData()
for i = 1, #data do
if (data[i] == spell) then
tremove (data, i)
break
end
end
self:GetParent():Refresh()
end
local scroll_createline = function (self, index)
local line = CreateFrame ("button", "$parentLine" .. index, self)
line:SetPoint ("topleft", self, "topleft", 0, -((index-1)*(scroll_line_height+1)))
line:SetSize (scroll_width, scroll_line_height)
line:SetScript ("OnEnter", line_onenter)
line:SetScript ("OnLeave", line_onleave)
line:SetScript ("OnClick", line_onclick)
line:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
line:SetBackdropColor (0, 0, 0, 0.2)
local icon = line:CreateTexture ("$parentIcon", "overlay")
icon:SetSize (scroll_line_height, scroll_line_height)
local name = line:CreateFontString ("$parentName", "overlay", "GameFontNormal")
icon:SetPoint ("left", line, "left", 2, 0)
name:SetPoint ("left", icon, "right", 2, 0)
line.icon = icon
line.name = name
return line
end
local scroll_refresh = function (self, data, offset, total_lines)
for i = 1, total_lines do
local index = i + offset
local aura = data [index]
if (aura) then
local line = self:GetLine (i)
local name, _, icon = GetSpellInfo (aura)
line.value = aura
if (name) then
line.name:SetText (name)
line.icon:SetTexture (icon)
else
line.name:SetText (aura)
line.icon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]])
end
end
end
end
local buffs_added = self:CreateScrollBox (f_manual, "$parentBuffsAdded", scroll_refresh, f.db.aura_tracker.buff, scroll_width, scroll_height, scroll_lines, scroll_line_height)
buffs_added:SetPoint ("topleft", f_manual, "topleft", 0, y)
buffs_added:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
buffs_added:SetBackdropColor (0, 0, 0, 0.2)
buffs_added:SetBackdropBorderColor (0, 0, 0, 1)
for i = 1, scroll_lines do
buffs_added:CreateLine (scroll_createline)
end
local debuffs_added = self:CreateScrollBox (f_manual, "$parentDebuffsAdded", scroll_refresh, f.db.aura_tracker.debuff, scroll_width, scroll_height, scroll_lines, scroll_line_height)
debuffs_added:SetPoint ("topleft", f_manual, "topleft", width+30, y)
debuffs_added:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
debuffs_added:SetBackdropColor (0, 0, 0, 0.2)
debuffs_added:SetBackdropBorderColor (0, 0, 0, 1)
for i = 1, scroll_lines do
debuffs_added:CreateLine (scroll_createline)
end
f.buffs_added = buffs_added
f.debuffs_added = debuffs_added
local buffs_added_name = DF:CreateLabel (buffs_added, "Buffs", 12, "silver")
buffs_added_name:SetTemplate (DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
buffs_added_name:SetPoint ("bottomleft", buffs_added, "topleft", 0, 2)
buffs_added.Title = buffs_added_name
local debuffs_added_name = DF:CreateLabel (debuffs_added, "Debuffs", 12, "silver")
debuffs_added_name:SetTemplate (DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
debuffs_added_name:SetPoint ("bottomleft", debuffs_added, "topleft", 0, 2)
debuffs_added.Title = debuffs_added_name
--> build the text entry to type the spellname
local new_buff_string = self:CreateLabel (f_manual, "Add Buff")
local new_debuff_string = self:CreateLabel (f_manual, "Add Debuff")
local new_buff_entry = self:CreateTextEntry (f_manual, function()end, 200, 20, "NewBuffTextBox", _, _, options_dropdown_template)
local new_debuff_entry = self:CreateTextEntry (f_manual, function()end, 200, 20, "NewDebuffTextBox", _, _, options_dropdown_template)
new_buff_entry:SetJustifyH ("left")
new_debuff_entry:SetJustifyH ("left")
DF:SetAutoCompleteWithSpells (new_buff_entry)
DF:SetAutoCompleteWithSpells (new_debuff_entry)
local add_buff_button = self:CreateButton (f_manual, function()
local text = new_buff_entry.text
new_buff_entry:SetText ("")
new_buff_entry:ClearFocus()
if (text ~= "") then
tinsert (f.db.aura_tracker.buff, text)
buffs_added:Refresh()
end
end, 100, 20, "Add Buff", nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"))
local add_debuff_button = self:CreateButton (f_manual, function()
local text = new_debuff_entry.text
new_debuff_entry:SetText ("")
new_debuff_entry:ClearFocus()
if (text ~= "") then
tinsert (f.db.aura_tracker.debuff, text)
debuffs_added:Refresh()
end
end, 100, 20, "Add Debuff", nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"))
new_buff_string:SetPoint ("topleft", f_manual, "topleft", 480, -40)
new_buff_entry:SetPoint ("topleft", new_buff_string, "bottomleft", 0, -2)
add_buff_button:SetPoint ("left", new_buff_entry, "right", 2, 0)
add_buff_button.tooltip = "Add the aura to be tracked.\n\nClick an aura on the list to remove it."
new_debuff_string:SetPoint ("topleft", f_manual, "topleft", 480, -200)
new_debuff_entry:SetPoint ("topleft", new_debuff_string, "bottomleft", 0, -2)
add_debuff_button:SetPoint ("left", new_debuff_entry, "right", 2, 0)
add_debuff_button.tooltip = "Add the aura to be tracked.\n\nClick an aura on the list to remove it."
buffs_added:Refresh()
debuffs_added:Refresh()
return f
end
function DF:GetAllPlayerSpells (include_lower_case)
local playerSpells = {}
local tab, tabTex, offset, numSpells = GetSpellTabInfo (2)
for i = 1, numSpells do
local index = offset + i
local spellType, spellId = GetSpellBookItemInfo (index, "player")
if (spellType == "SPELL") then
local spellName = GetSpellInfo (spellId)
tinsert (playerSpells, spellName)
if (include_lower_case) then
tinsert (playerSpells, lower (spellName))
end
end
end
return playerSpells
end
function DF:SetAutoCompleteWithSpells (textentry)
textentry:SetHook ("OnEditFocusGained", function()
local playerSpells = DF:GetAllPlayerSpells (true)
textentry.WordList = playerSpells
end)
textentry:SetAsAutoComplete ("WordList")
end
--check for aura
-- add aura
--handle savedvariables
--remove a aura
--handle UNIT_AURA event
+35 -1
View File
@@ -1,5 +1,5 @@
local dversion = 24
local dversion = 27
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary (major, minor)
@@ -110,6 +110,7 @@ local embed_functions = {
"SetFrameworkDebugState",
"FindHighestParent",
"OpenInterfaceProfile",
"CreateInCombatTexture",
}
DF.table = {}
@@ -562,6 +563,10 @@ end
slider.widget_type = "range"
slider:SetHook ("OnValueChange", widget_table.set)
if (widget_table.thumbscale) then
slider:SetThumbSize (slider.thumb:GetWidth()*widget_table.thumbscale, nil)
end
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)
slider:SetPoint ("left", label, "right", 2)
label:SetPoint (cur_x, cur_y)
@@ -683,6 +688,34 @@ end
end
end)
function DF:CreateInCombatTexture (frame)
if (DF.debug and not frame) then
error ("Details! Framework: CreateInCombatTexture invalid frame on parameter 1.")
end
local in_combat_background = DF:CreateImage (frame)
in_combat_background:SetColorTexture (.6, 0, 0, .1)
in_combat_background:Hide()
local in_combat_label = Plater:CreateLabel (frame, "you are in combat", 24, "silver")
in_combat_label:SetPoint ("right", in_combat_background, "right", -10, 0)
in_combat_label:Hide()
frame:RegisterEvent ("PLAYER_REGEN_DISABLED")
frame:RegisterEvent ("PLAYER_REGEN_ENABLED")
frame:SetScript ("OnEvent", function (self, event)
if (event == "PLAYER_REGEN_DISABLED") then
in_combat_background:Show()
in_combat_label:Show()
elseif (event == "PLAYER_REGEN_ENABLED") then
in_combat_background:Hide()
in_combat_label:Hide()
end
end)
return in_combat_background
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> tutorials
@@ -1051,6 +1084,7 @@ DF.GlobalWidgetControlNames = {
image = "DF_ImageMetaFunctions",
slider = "DF_SliderMetaFunctions",
split_bar = "DF_SplitBarMetaFunctions",
aura_tracker = "DF_AuraTracker",
}
function DF:AddMemberForWidget (widgetName, memberType, memberName, func)
+1
View File
@@ -20,4 +20,5 @@
<Include file="panel.xml"/>
<Script file="pictureedit.lua"/>
<Script file="auras.lua"/>
</Ui>
+2 -2
View File
@@ -510,11 +510,11 @@ local BarMetaFunctions = _G [DF.GlobalWidgetControlNames ["normal_bar"]]
function BarMetaFunctions:OnTimerEnd()
local capsule = self
local kill = capsule:RunHooksForWidget ("OnTimerEnd", self.widget, button, capsule)
local kill = capsule:RunHooksForWidget ("OnTimerEnd", self.widget, capsule)
if (kill) then
return
end
self.timer_texture:Hide()
self.timer_textureR:Hide()
self.div_timer:Hide()
+257 -4
View File
@@ -3330,10 +3330,263 @@ end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- ~listbox
local simple_list_box_ResetWidgets = function (self)
for _, widget in ipairs (self.widgets) do
widget:Hide()
end
self.nextWidget = 1
end
local simple_list_box_onenter = function (self, capsule)
self:GetParent().options.onenter (self, capsule, capsule.value)
end
local simple_list_box_onleave = function (self, capsule)
self:GetParent().options.onleave (self, capsule, capsule.value)
GameTooltip:Hide()
end
local simple_list_box_GetOrCreateWidget = function (self)
local index = self.nextWidget
local widget = self.widgets [index]
if (not widget) then
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"))
widget:SetHook ("OnEnter", simple_list_box_onenter)
widget:SetHook ("OnLeave", simple_list_box_onleave)
widget.textcolor = self.options.textcolor
tinsert (self.widgets, widget)
end
self.nextWidget = self.nextWidget + 1
return widget
end
local simple_list_box_RefreshWidgets = function (self)
self:ResetWidgets()
local amt = 0
for value, _ in pairs (self.list_table) do
local widget = self:GetOrCreateWidget()
widget:SetPoint ("topleft", self, "topleft", 1, -self.options.row_height * (self.nextWidget-2) - 4)
widget:SetPoint ("topright", self, "topright", -1, -self.options.row_height * (self.nextWidget-2) - 4)
widget:SetClickFunction (self.func, value)
widget.value = value
if (self.options.icon) then
if (type (self.options.icon) == "string" or type (self.options.icon) == "number") then
widget:SetIcon (self.options.icon, self.options.row_height, self.options.row_height)
elseif (type (self.options.icon) == "function") then
local icon = self.options.icon (value)
if (icon) then
widget:SetIcon (icon, self.options.row_height, self.options.row_height)
end
end
else
widget:SetIcon ("", self.options.row_height, self.options.row_height)
end
if (self.options.text) then
if (type (self.options.text) == "function") then
local text = self.options.text (value)
if (text) then
widget:SetText (text)
else
widget:SetText ("")
end
else
widget:SetText (self.options.text or "")
end
else
widget:SetText ("")
end
widget.value = value
widget:Show()
amt = amt + 1
end
if (amt == 0) then
self.EmptyLabel:Show()
else
self.EmptyLabel:Hide()
end
end
local backdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1}
local default_options = {
height = 400,
row_height = 16,
width = 230,
icon = false,
text = "",
textcolor = "wheat",
onenter = function (self, capsule)
if (capsule) then
capsule.textcolor = "white"
end
end,
onleave = function (self, capsule)
if (capsule) then
capsule.textcolor = self:GetParent().options.textcolor
end
GameTooltip:Hide()
end,
}
local simple_list_box_SetData = function (self, t)
self.list_table = t
end
function DF:CreateSimpleListBox (parent, name, title, empty_text, list_table, onclick, options)
local f = CreateFrame ("frame", name, parent)
f.ResetWidgets = simple_list_box_ResetWidgets
f.GetOrCreateWidget = simple_list_box_GetOrCreateWidget
f.Refresh = simple_list_box_RefreshWidgets
f.SetData = simple_list_box_SetData
f.nextWidget = 1
f.list_table = list_table
f.func = function (self, button, value)
onclick (value)
f:Refresh()
end
f.widgets = {}
f:SetBackdrop (backdrop)
f:SetBackdropColor (0, 0, 0, 0.3)
f:SetBackdropBorderColor (0, 0, 0, 0.5)
f.options = options or {}
self.table.deploy (f.options, default_options)
f:SetSize (f.options.width + 2, f.options.height)
local name = DF:CreateLabel (f, title, 12, "silver")
name:SetTemplate (DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
name:SetPoint ("bottomleft", f, "topleft", 0, 2)
f.Title = name
local emptyLabel = DF:CreateLabel (f, empty_text, 12, "gray")
emptyLabel:SetAlpha (.6)
emptyLabel:SetSize (f.options.width-10, f.options.height)
emptyLabel:SetPoint ("center", 0, 0)
emptyLabel:Hide()
emptyLabel.align = "center"
f.EmptyLabel = emptyLabel
return f
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- ~scrollbox
-- preciso de uma fauxscroll que seja facil de lidar
-- ele cria scroll aqui, preciso falar a função que cria a linha e a função que atualiza
-- precisa passsar o tamanho em height width quantas barras vai mostrar
-- search box incluso opcionalmente
DF.SortFunctions = {}
local SortMember = ""
local SortByMember = function (t1, t2)
return t1[SortMember] > t2[SortMember]
end
local SortByMemberReverse = function (t1, t2)
return t1[SortMember] < t2[SortMember]
end
DF.SortFunctions.Sort = function (self, t, by, is_reverse)
SortMember = by
if (not is_reverse) then
table.sort (t, SortByMember)
else
table.sort (t, SortByMemberReverse)
end
end
DF.ScrollBoxFunctions = {}
DF.ScrollBoxFunctions.Refresh = function (self)
for _, frame in ipairs (self.Frames) do
frame:Hide()
frame._InUse = nil
end
local offset = 0
if (self.IsFauxScroll) then
FauxScrollFrame_Update (self, #self.data, self.LineAmount, self.LineHeight+1)
offset = FauxScrollFrame_GetOffset (self)
end
local okay, totalLines = pcall (self.refresh_func, self, self.data, offset, #self.Frames)
if (not okay) then
error ("Details! FrameWork: Refresh(): " .. result)
end
for _, frame in ipairs (self.Frames) do
if (not frame._InUse) then
frame:Hide()
else
frame:Show()
end
end
self:Show()
return self.Frames
end
DF.ScrollBoxFunctions.OnVerticalScroll = function (self, offset)
FauxScrollFrame_OnVerticalScroll (self, offset, self.LineHeight, self.Refresh)
return true
end
DF.ScrollBoxFunctions.CreateLine = function (self, func)
local okay, newLine = pcall (func, self, #self.Frames+1)
if (okay) then
tinsert (self.Frames, newLine)
return newLine
else
error ("Details! FrameWork: CreateLine(): " .. newLine)
end
end
DF.ScrollBoxFunctions.GetLine = function (self, line_index)
local line = self.Frames [line_index]
if (line) then
line._InUse = true
end
return line
end
DF.ScrollBoxFunctions.SetData = function (self, data)
self.data = data
end
DF.ScrollBoxFunctions.GetData = function (self)
return self.data
end
function DF:CreateScrollBox (parent, name, refresh_func, data, width, height, line_amount, line_height)
local scroll = CreateFrame ("scrollframe", name, parent, "FauxScrollFrameTemplate")
scroll:SetSize (width, height)
scroll.LineAmount = line_amount
scroll.LineHeight = line_height
scroll.IsFauxScroll = true
scroll.Frames = {}
DF:Mixin (scroll, DF.SortFunctions)
DF:Mixin (scroll, DF.ScrollBoxFunctions)
scroll.refresh_func = refresh_func
scroll.data = data
scroll:SetScript ("OnVerticalScroll", scroll.OnVerticalScroll)
return scroll
end