diff --git a/Libs/DF/button.lua b/Libs/DF/button.lua index dd69d21e6..9839b6e8a 100644 --- a/Libs/DF/button.lua +++ b/Libs/DF/button.lua @@ -21,6 +21,8 @@ do local metaPrototype = { WidgetType = "button", SetHook = DF.SetHook, + HasHook = DF.HasHook, + ClearHooks = DF.ClearHooks, RunHooksForWidget = DF.RunHooksForWidget, } diff --git a/Libs/DF/fw.lua b/Libs/DF/fw.lua index c77e8fd56..d93e23965 100644 --- a/Libs/DF/fw.lua +++ b/Libs/DF/fw.lua @@ -1,5 +1,5 @@ -local dversion = 176 +local dversion = 178 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary (major, minor) @@ -19,6 +19,7 @@ local upper = string.upper local string_match = string.match local tinsert = _G.tinsert local abs = _G.abs +local tremove = _G.tremove local UnitPlayerControlled = UnitPlayerControlled local UnitIsTapDenied = UnitIsTapDenied @@ -934,9 +935,15 @@ end ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --> menus + + local disable_on_combat = {} + local getMenuWidgetVolative = function(parent, widgetType, indexTable) + + local widget + if (widgetType == "label") then - local widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] if (not widget) then widget = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType], "overlay") tinsert(parent.widget_list, widget) @@ -944,10 +951,9 @@ end end indexTable[widgetType] = indexTable[widgetType] + 1 - return widget elseif (widgetType == "dropdown") then - local widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] if (not widget) then widget = DF:CreateDropDown (parent, function() return {} end, nil, 140, 18, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) @@ -961,42 +967,97 @@ end end indexTable[widgetType] = indexTable[widgetType] + 1 - return widget elseif (widgetType == "switch") then - local widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] if (not widget) then - local widget = DF:CreateSwitch (parent, nil, true, 20, 20, nil, nil, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) + widget = DF:CreateSwitch (parent, nil, true, 20, 20, nil, nil, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") tinsert(parent.widget_list, widget) tinsert(parent.widget_list_by_type[widgetType], widget) else widget:ClearHooks() - end indexTable[widgetType] = indexTable[widgetType] + 1 - return widget elseif (widgetType == "slider") then + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + + if (not widget) then + widget = DF:CreateSlider (parent, 140, 20, 1, 2, 1, 1, false, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) + widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") + + tinsert(parent.widget_list, widget) + tinsert(parent.widget_list_by_type[widgetType], widget) + else + widget:ClearHooks() + end + indexTable[widgetType] = indexTable[widgetType] + 1 elseif (widgetType == "color") then + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + + if (not widget) then + widget = DF:CreateColorPickButton (parent, "$parentWidget" .. widgetType .. indexTable[widgetType], nil, function()end, 1) + widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") + tinsert(parent.widget_list, widget) + tinsert(parent.widget_list_by_type[widgetType], widget) + else + widget:ClearHooks() + end + + indexTable[widgetType] = indexTable[widgetType] + 1 elseif (widgetType == "button") then + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + + if (not widget) then + widget = DF:CreateButton (parent, function()end, 120, 18, "", nil, nil, nil, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) + widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") + tinsert(parent.widget_list, widget) + tinsert(parent.widget_list_by_type[widgetType], widget) + else + widget:ClearHooks() + end + + indexTable[widgetType] = indexTable[widgetType] + 1 elseif (widgetType == "textentry") then + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + + if (not widget) then + widget = DF:CreateTextEntry (parent, function()end, 120, 18, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) + widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") - + tinsert(parent.widget_list, widget) + tinsert(parent.widget_list_by_type[widgetType], widget) + else + widget:ClearHooks() + end + + indexTable[widgetType] = indexTable[widgetType] + 1 + end + + --if the widget is inside the no combat table, remove it + for i = 1, #disable_on_combat do + if (disable_on_combat[i] == widget) then + tremove(disable_on_combat, i) + break + end end + + return widget end --volatile menu can be called several times, each time all settings are reset and a new menu is built using the same widgets function DF:BuildMenuVolatile (parent, menu, x_offset, y_offset, height, use_two_points, text_template, dropdown_template, switch_template, switch_is_box, slider_template, button_template, value_change_hook) + if (not parent.widget_list) then DF:SetAsOptionsPanel (parent) end @@ -1021,128 +1082,334 @@ end for index, widget_table in ipairs(menu) do - --step a line - if (widget_table.type == "blank" or widget_table.type == "space") then - -- do nothing + if (not widget_table.novolatile) then - elseif (widget_table.type == "label" or widget_table.type == "text") then + --step a line + if (widget_table.type == "blank" or widget_table.type == "space") then + -- do nothing - local label = getMenuWidgetVolative(parent, "label", widgetIndexes) + elseif (widget_table.type == "label" or widget_table.type == "text") then - label.text = widget_table.get() or widget_table.text or "" - label.color = widget_table.color - label.fontface = widget_table.font + local label = getMenuWidgetVolative(parent, "label", widgetIndexes) + widget_created = label - if (widget_table.text_template or text_template) then - label:SetTemplate(widget_table.text_template or text_template) - else - label.fontsize = widget_table.size or 10 - end + label.text = widget_table.get() or widget_table.text or "" + label.color = widget_table.color + label.fontface = widget_table.font - label._get = widget_table.get - label.widget_type = "label" - label:ClearAllPoints() - label:SetPoint (cur_x, cur_y) + if (widget_table.text_template or text_template) then + label:SetTemplate(widget_table.text_template or text_template) + else + label.fontsize = widget_table.size or 10 + end - if (widget_table.id) then - parent.widgetids [widget_table.id] = label - end + label._get = widget_table.get + label.widget_type = "label" + label:ClearAllPoints() + label:SetPoint (cur_x, cur_y) - --dropdowns - elseif (widget_table.type == "select" or widget_table.type == "dropdown") then + if (widget_table.id) then + parent.widgetids [widget_table.id] = label + end - local dropdown = getMenuWidgetVolative(parent, "dropdown", widgetIndexes) - dropdown:SetFunction(widget_table.values) - dropdown:Refresh() - dropdown:Select (widget_table.get()) - dropdown:SetTemplate (dropdown_template) + --dropdowns + elseif (widget_table.type == "select" or widget_table.type == "dropdown") then - dropdown.tooltip = widget_table.desc - dropdown._get = widget_table.get - dropdown.widget_type = "select" + local dropdown = getMenuWidgetVolative(parent, "dropdown", widgetIndexes) + widget_created = dropdown + dropdown:SetFunction(widget_table.values) + dropdown:Refresh() + dropdown:Select (widget_table.get()) + dropdown:SetTemplate (dropdown_template) - dropdown.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") - dropdown.hasLabel:SetTemplate(widget_table.text_template or text_template) - dropdown:ClearAllPoints() - dropdown:SetPoint ("left", dropdown.hasLabel, "right", 2) - dropdown.hasLabel:ClearAllPoints() - dropdown.hasLabel:SetPoint (cur_x, cur_y) + dropdown.tooltip = widget_table.desc + dropdown._get = widget_table.get + dropdown.widget_type = "select" - --> global callback - if (value_change_hook) then - dropdown:SetHook ("OnOptionSelected", value_change_hook) - end - - --> hook list (hook list is wiped when getting the widget) - if (widget_table.hooks) then - for hookName, hookFunc in pairs (widget_table.hooks) do - dropdown:SetHook (hookName, hookFunc) + + dropdown.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + dropdown.hasLabel:SetTemplate(widget_table.text_template or text_template) + dropdown:ClearAllPoints() + dropdown:SetPoint ("left", dropdown.hasLabel, "right", 2) + dropdown.hasLabel:ClearAllPoints() + dropdown.hasLabel:SetPoint (cur_x, cur_y) + + --> global callback + if (value_change_hook) then + dropdown:SetHook ("OnOptionSelected", value_change_hook) + end + + --> hook list (hook list is wiped when getting the widget) + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + dropdown:SetHook (hookName, hookFunc) + end end - end - if (widget_table.id) then - parent.widgetids [widget_table.id] = dropdown - end - - local size = dropdown.hasLabel.widget:GetStringWidth() + 140 + 4 - if (size > max_x) then - max_x = size - end + if (widget_table.id) then + parent.widgetids [widget_table.id] = dropdown + end + + local size = dropdown.hasLabel.widget:GetStringWidth() + 140 + 4 + if (size > max_x) then + max_x = size + end - --switchs - elseif (widget_table.type == "toggle" or widget_table.type == "switch") then + --switchs + elseif (widget_table.type == "toggle" or widget_table.type == "switch") then - local switch = getMenuWidgetVolative(parent, "switch", widgetIndexes) + local switch = getMenuWidgetVolative(parent, "switch", widgetIndexes) + widget_created = switch - switch:SetValue(widget_table.get()) - switch:SetTemplate(switch_template) - switch:SetAsCheckBox() --it's always a checkbox on volatile menu + switch:SetValue(widget_table.get()) + switch:SetTemplate(switch_template) + switch:SetAsCheckBox() --it's always a checkbox on volatile menu - switch.tooltip = widget_table.desc - switch._get = widget_table.get - switch.widget_type = "toggle" - switch.OnSwitch = widget_table.set - - if (value_change_hook) then - switch:SetHook ("OnSwitch", value_change_hook) - end - - --> hook list - if (widget_table.hooks) then - for hookName, hookFunc in pairs (widget_table.hooks) do - switch:SetHook (hookName, hookFunc) + switch.tooltip = widget_table.desc + switch._get = widget_table.get + switch.widget_type = "toggle" + switch.OnSwitch = widget_table.set + + if (value_change_hook) then + switch:SetHook ("OnSwitch", value_change_hook) + end + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + switch:SetHook (hookName, hookFunc) + end end - end - switch.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") - switch.hasLabel:SetTemplate(widget_table.text_template or text_template) + switch.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + switch.hasLabel:SetTemplate(widget_table.text_template or text_template) - switch:ClearAllPoints() - switch.hasLabel:ClearAllPoints() + switch:ClearAllPoints() + switch.hasLabel:ClearAllPoints() - if (widget_table.boxfirst) then - switch:SetPoint (cur_x, cur_y) - switch.hasLabel:SetPoint ("left", switch, "right", 2) - else - switch.hasLabel:SetPoint (cur_x, cur_y) - switch:SetPoint ("left", switch.hasLabel, "right", 2) - end + if (widget_table.boxfirst) then + switch:SetPoint (cur_x, cur_y) + switch.hasLabel:SetPoint ("left", switch, "right", 2) + else + switch.hasLabel:SetPoint (cur_x, cur_y) + switch:SetPoint ("left", switch.hasLabel, "right", 2) + end - if (widget_table.id) then - parent.widgetids [widget_table.id] = switch + if (widget_table.id) then + parent.widgetids [widget_table.id] = switch + end + + local size = switch.hasLabel:GetStringWidth() + 60 + 4 + if (size > max_x) then + max_x = size + end + + --slider + elseif (widget_table.type == "range" or widget_table.type == "slider") then + + local slider = getMenuWidgetVolative(parent, "slider", widgetIndexes) + widget_created = slider + + slider.slider:SetMinMaxValues (widget_table.min, widget_table.max) + slider.slider:SetValue (widget_table.get()) + slider.ivalue = slider.slider:GetValue() + + if (widget_table.usedecimals) then + slider.slider:SetValueStep (0.01) + else + slider.slider:SetValueStep (widget_table.step) + end + + slider:SetTemplate(slider_template) + + slider.tooltip = widget_table.desc + slider._get = widget_table.get + slider.widget_type = "range" + slider:SetHook ("OnValueChange", widget_table.set) + + if (value_change_hook) then + slider:SetHook ("OnValueChange", value_change_hook) + end + + if (widget_table.thumbscale) then + slider:SetThumbSize (slider.thumb.originalWidth * widget_table.thumbscale, nil) + else + slider:SetThumbSize (slider.thumb.originalWidth * 1.3, nil) + end + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + slider:SetHook (hookName, hookFunc) + end + end + + slider.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + slider.hasLabel:SetTemplate(widget_table.text_template or text_template) + + slider:SetPoint ("left", slider.hasLabel, "right", 2) + slider.hasLabel:SetPoint (cur_x, cur_y) + + if (widget_table.id) then + parent.widgetids [widget_table.id] = slider + end + + local size = slider.hasLabel:GetStringWidth() + 140 + 6 + if (size > max_x) then + max_x = size + end + + --color + elseif (widget_table.type == "color" or widget_table.type == "color") then + + local colorpick = getMenuWidgetVolative(parent, "color", widgetIndexes) + widget_created = colorpick + + colorpick.color_callback = widget_table.set --callback + colorpick:SetTemplate(button_template) + + colorpick.tooltip = widget_table.desc + colorpick._get = widget_table.get + colorpick.widget_type = "color" + + local default_value, g, b, a = widget_table.get() + if (type (default_value) == "table") then + colorpick:SetColor (unpack (default_value)) + else + colorpick:SetColor (default_value, g, b, a) + end + + if (value_change_hook) then + colorpick:SetHook ("OnColorChanged", value_change_hook) + end + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + colorpick:SetHook (hookName, hookFunc) + end + end + + colorpick.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + colorpick.hasLabel:SetTemplate(widget_table.text_template or text_template) + + colorpick:SetPoint ("left", colorpick.hasLabel, "right", 2) + colorpick.hasLabel:SetPoint (cur_x, cur_y) + + if (widget_table.id) then + parent.widgetids [widget_table.id] = colorpick + end + + local size = colorpick.hasLabel:GetStringWidth() + 60 + 4 + if (size > max_x) then + max_x = size + end + + --button + elseif (widget_table.type == "execute" or widget_table.type == "button") then + + local button = getMenuWidgetVolative(parent, "button", widgetIndexes) + widget_created = button + + button:SetTemplate(button_template) + button:SetSize(widget_table.width or 120, widget_table.height or 18) + button:SetClickFunction(widget_table.func, widget_table.param1, widget_table.param2) + + local textTemplate = widget_table.text_template or text_template or DF.font_templates ["ORANGE_FONT_TEMPLATE"] + button.textcolor = textTemplate.color + button.textfont = textTemplate.font + button.textsize = textTemplate.size + button.text = widget_table.name + + button:SetPoint (cur_x, cur_y) + button.tooltip = widget_table.desc + button.widget_type = "execute" + + --> execute doesn't trigger global callback + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + button:SetHook (hookName, hookFunc) + end + end + + if (widget_table.id) then + parent.widgetids [widget_table.id] = button + end + + local size = button:GetWidth() + 4 + if (size > max_x) then + max_x = size + end + + --textentry + elseif (widget_table.type == "textentry") then + + local textentry = getMenuWidgetVolative(parent, "textentry", widgetIndexes) + widget_created = textentry + + textentry:SetCommitFunction(widget_table.func) + textentry:SetTemplate(widget_table.template or widget_table.button_template or button_template) + textentry:SetSize(widget_table.width or 120, widget_table.height or 18) + + textentry.tooltip = widget_table.desc + textentry.text = widget_table.get() + textentry._get = widget_table.get + textentry.widget_type = "textentry" + textentry:SetHook ("OnEnterPressed", widget_table.set) + textentry:SetHook ("OnEditFocusLost", widget_table.set) + + textentry.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + textentry.hasLabel:SetTemplate(widget_table.text_template or text_template) + textentry:SetPoint ("left", textentry.hasLabel, "right", 2) + textentry.hasLabel:SetPoint (cur_x, cur_y) + + --> text entry doesn't trigger global callback + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + textentry:SetHook (hookName, hookFunc) + end + end + + if (widget_table.id) then + parent.widgetids [widget_table.id] = textentry + end + + local size = textentry.hasLabel:GetStringWidth() + 60 + 4 + if (size > max_x) then + max_x = size + end + + end --end loop + + if (widget_table.nocombat) then + tinsert (disable_on_combat, widget_created) + end + + if (widget_table.spacement) then + cur_y = cur_y - 30 + else + cur_y = cur_y - 20 end - local size = switch.hasLabel:GetStringWidth() + 60 + 4 - if (size > max_x) then - max_x = size + if (widget_table.type == "breakline" or cur_y < height) then + cur_y = y_offset + cur_x = cur_x + max_x + 30 + line_widgets_created = 0 + max_x = 0 end + + widget_created:Show() end end + + DF.RefreshUnsafeOptionsWidgets() end - local disable_on_combat = {} - 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, value_change_hook) if (not parent.widget_list) then @@ -3380,6 +3647,24 @@ function DF:GetRangeCheckSpellForSpec(specId) end +--key is instanceId from GetInstanceInfo() +-- /dump GetInstanceInfo() +DF.BattlegroundSizes = { + [2245] = 15, --Deepwind Gorge + [2106] = 10, --Warsong Gulch + [2107] = 15, --Arathi Basin + [566] = 15, --Eye of the Storm + [30] = 40, --Alterac Valley + [628] = 40, --Isle of Conquest + [761] = 10, --The Battle for Gilneas + [726] = 10, --Twin Peaks + [727] = 10, --Silvershard Mines + [998] = 10, --Temple of Kotmogu + [2118] = 40, --Battle for Wintergrasp + [1191] = 25, --Ashran + [1803] = 10, --Seething Shore +} + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --> delta seconds reader diff --git a/Libs/DF/label.lua b/Libs/DF/label.lua index 8441960fc..bba5c41b3 100644 --- a/Libs/DF/label.lua +++ b/Libs/DF/label.lua @@ -288,7 +288,7 @@ function DF:NewLabel (parent, container, name, member, text, font, size, color, container = container.widget end - font = font or "GameFontHighlightSmall" + font = font == "" and "GameFontHighlightSmall" or font or "GameFontHighlightSmall" LabelObject.label = parent:CreateFontString (name, layer or "OVERLAY", font) LabelObject.widget = LabelObject.label diff --git a/Libs/DF/slider.lua b/Libs/DF/slider.lua index bd8719d9f..1555028c2 100644 --- a/Libs/DF/slider.lua +++ b/Libs/DF/slider.lua @@ -22,7 +22,10 @@ do local metaPrototype = { WidgetType = "slider", SetHook = DF.SetHook, + HasHook = DF.HasHook, + ClearHooks = DF.ClearHooks, RunHooksForWidget = DF.RunHooksForWidget, + } _G [DF.GlobalWidgetControlNames ["slider"]] = _G [DF.GlobalWidgetControlNames ["slider"]] or metaPrototype @@ -1177,6 +1180,8 @@ function DF:NewSlider (parent, container, name, member, w, h, min, max, step, de SliderObject.thumb = SliderObject.slider:CreateTexture (nil, "artwork") SliderObject.thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob") SliderObject.thumb:SetSize (30+(h*0.2), h*1.2) + SliderObject.thumb.originalWidth = SliderObject.thumb:GetWidth() + SliderObject.thumb.originalHeight =SliderObject.thumb:GetHeight() SliderObject.thumb:SetAlpha (0.7) SliderObject.slider:SetThumbTexture (SliderObject.thumb) SliderObject.slider.thumb = SliderObject.thumb diff --git a/Libs/DF/textentry.lua b/Libs/DF/textentry.lua index 0bfcf45a8..fd289be93 100644 --- a/Libs/DF/textentry.lua +++ b/Libs/DF/textentry.lua @@ -22,6 +22,8 @@ do local metaPrototype = { WidgetType = "textentry", SetHook = DF.SetHook, + HasHook = DF.HasHook, + ClearHooks = DF.ClearHooks, RunHooksForWidget = DF.RunHooksForWidget, } @@ -304,6 +306,12 @@ DF.TextEntryCounter = DF.TextEntryCounter or 1 end end end + + function TextEntryMetaFunctions:SetCommitFunction(func) + if (type(func) == "function") then + self.func = func + end + end ------------------------------------------------------------------------------------------------------------ --> scripts and hooks