comparison Libs/DF/panel.lua @ 58:0682d738499b v8.0.1.058

- 8.0.1 Update.
author Tercio
date Fri, 20 Jul 2018 19:04:12 -0300
parents 7c0f819a85c6
children
comparison
equal deleted inserted replaced
57:b1c62eed8999 58:0682d738499b
26 26
27 _G [DF.GlobalWidgetControlNames ["panel"]] = _G [DF.GlobalWidgetControlNames ["panel"]] or metaPrototype 27 _G [DF.GlobalWidgetControlNames ["panel"]] = _G [DF.GlobalWidgetControlNames ["panel"]] or metaPrototype
28 end 28 end
29 29
30 local PanelMetaFunctions = _G [DF.GlobalWidgetControlNames ["panel"]] 30 local PanelMetaFunctions = _G [DF.GlobalWidgetControlNames ["panel"]]
31
32 --> mixin for options functions
33 DF.OptionsFunctions = {
34 SetOption = function (self, optionName, optionValue)
35 if (self.options) then
36 self.options [optionName] = optionValue
37 else
38 self.options = {}
39 self.options [optionName] = optionValue
40 end
41 end,
42
43 GetOption = function (self, optionName)
44 return self.options and self.options [optionName]
45 end,
46
47 GetAllOptions = function (self)
48 if (self.options) then
49 local optionsTable = {}
50 for key, _ in pairs (self.options) do
51 optionsTable [#optionsTable + 1] = key
52 end
53 return optionsTable
54 else
55 return {}
56 end
57 end,
58
59 BuildOptionsTable = function (self, defaultOptions, userOptions)
60 self.options = self.options or {}
61 DF.table.deploy (self.options, userOptions or {})
62 DF.table.deploy (self.options, defaultOptions or {})
63 end
64 }
31 65
32 ------------------------------------------------------------------------------------------------------------ 66 ------------------------------------------------------------------------------------------------------------
33 --> metatables 67 --> metatables
34 68
35 PanelMetaFunctions.__call = function (_table, value) 69 PanelMetaFunctions.__call = function (_table, value)
1214 1248
1215 local string_lower = string.lower 1249 local string_lower = string.lower
1216 1250
1217 DF.IconPickFrame = CreateFrame ("frame", "DetailsFrameworkIconPickFrame", UIParent) 1251 DF.IconPickFrame = CreateFrame ("frame", "DetailsFrameworkIconPickFrame", UIParent)
1218 tinsert (UISpecialFrames, "DetailsFrameworkIconPickFrame") 1252 tinsert (UISpecialFrames, "DetailsFrameworkIconPickFrame")
1219 DF.IconPickFrame:SetFrameStrata ("DIALOG") 1253 DF.IconPickFrame:SetFrameStrata ("TOOLTIP")
1220 1254
1221 DF.IconPickFrame:SetPoint ("center", UIParent, "center") 1255 DF.IconPickFrame:SetPoint ("center", UIParent, "center")
1222 DF.IconPickFrame:SetWidth (350) 1256 DF.IconPickFrame:SetWidth (350)
1223 DF.IconPickFrame:SetHeight (227) 1257 DF.IconPickFrame:SetHeight (277)
1224 DF.IconPickFrame:EnableMouse (true) 1258 DF.IconPickFrame:EnableMouse (true)
1225 DF.IconPickFrame:SetMovable (true) 1259 DF.IconPickFrame:SetMovable (true)
1226 1260
1261 DF:CreateTitleBar (DF.IconPickFrame, "Icon Picker")
1262
1227 DF.IconPickFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) 1263 DF.IconPickFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
1228 1264
1229 DF.IconPickFrame:SetBackdropBorderColor (0, 0, 0) 1265 DF.IconPickFrame:SetBackdropBorderColor (0, 0, 0)
1230 DF.IconPickFrame:SetBackdropColor (24/255, 24/255, 24/255, .8) 1266 DF.IconPickFrame:SetBackdropColor (24/255, 24/255, 24/255, .8)
1231 DF.IconPickFrame:SetFrameLevel (1) 1267 DF.IconPickFrame:SetFrameLevel (5000)
1232 1268
1233 DF.IconPickFrame:SetScript ("OnMouseDown", function (self) 1269 DF.IconPickFrame:SetScript ("OnMouseDown", function (self)
1234 if (not self.isMoving) then 1270 if (not self.isMoving) then
1235 DF.IconPickFrame:StartMoving() 1271 DF.IconPickFrame:StartMoving()
1236 self.isMoving = true 1272 self.isMoving = true
1247 DF.IconPickFrame.emptyFunction = function() end 1283 DF.IconPickFrame.emptyFunction = function() end
1248 DF.IconPickFrame.callback = DF.IconPickFrame.emptyFunction 1284 DF.IconPickFrame.callback = DF.IconPickFrame.emptyFunction
1249 1285
1250 DF.IconPickFrame.preview = CreateFrame ("frame", nil, UIParent) 1286 DF.IconPickFrame.preview = CreateFrame ("frame", nil, UIParent)
1251 DF.IconPickFrame.preview:SetFrameStrata ("tooltip") 1287 DF.IconPickFrame.preview:SetFrameStrata ("tooltip")
1288 DF.IconPickFrame.preview:SetFrameLevel (6001)
1252 DF.IconPickFrame.preview:SetSize (76, 76) 1289 DF.IconPickFrame.preview:SetSize (76, 76)
1290
1291 local preview_image_bg = DF:NewImage (DF.IconPickFrame.preview, nil, 76, 76)
1292 preview_image_bg:SetDrawLayer ("background", 0)
1293 preview_image_bg:SetAllPoints (DF.IconPickFrame.preview)
1294 preview_image_bg:SetColorTexture (0, 0, 0)
1295
1253 local preview_image = DF:NewImage (DF.IconPickFrame.preview, nil, 76, 76) 1296 local preview_image = DF:NewImage (DF.IconPickFrame.preview, nil, 76, 76)
1254 preview_image:SetAllPoints (DF.IconPickFrame.preview) 1297 preview_image:SetAllPoints (DF.IconPickFrame.preview)
1298
1255 DF.IconPickFrame.preview.icon = preview_image 1299 DF.IconPickFrame.preview.icon = preview_image
1256 DF.IconPickFrame.preview:Hide() 1300 DF.IconPickFrame.preview:Hide()
1257 1301
1302 --serach
1258 DF.IconPickFrame.searchLabel = DF:NewLabel (DF.IconPickFrame, nil, "$parentSearchBoxLabel", nil, "search:", font, size, color) 1303 DF.IconPickFrame.searchLabel = DF:NewLabel (DF.IconPickFrame, nil, "$parentSearchBoxLabel", nil, "search:", font, size, color)
1259 DF.IconPickFrame.searchLabel:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12, -20) 1304 DF.IconPickFrame.searchLabel:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12, -36)
1305 DF.IconPickFrame.searchLabel:SetTemplate (DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
1306
1260 DF.IconPickFrame.search = DF:NewTextEntry (DF.IconPickFrame, nil, "$parentSearchBox", nil, 140, 20) 1307 DF.IconPickFrame.search = DF:NewTextEntry (DF.IconPickFrame, nil, "$parentSearchBox", nil, 140, 20)
1261 DF.IconPickFrame.search:SetPoint ("left", DF.IconPickFrame.searchLabel, "right", 2, 0) 1308 DF.IconPickFrame.search:SetPoint ("left", DF.IconPickFrame.searchLabel, "right", 2, 0)
1309 DF.IconPickFrame.search:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
1310
1262 DF.IconPickFrame.search:SetHook ("OnTextChanged", function() 1311 DF.IconPickFrame.search:SetHook ("OnTextChanged", function()
1263 DF.IconPickFrame.searching = DF.IconPickFrame.search:GetText() 1312 DF.IconPickFrame.searching = DF.IconPickFrame.search:GetText()
1264 if (DF.IconPickFrame.searching == "") then 1313 if (DF.IconPickFrame.searching == "") then
1265 DF.IconPickFrameScroll:Show() 1314 DF.IconPickFrameScroll:Show()
1266 DF.IconPickFrame.searching = nil 1315 DF.IconPickFrame.searching = nil
1271 DF.IconPickFrame.last_filter_index = 1 1320 DF.IconPickFrame.last_filter_index = 1
1272 DF.IconPickFrame.updateFunc() 1321 DF.IconPickFrame.updateFunc()
1273 end 1322 end
1274 end) 1323 end)
1275 1324
1325 --manually enter the icon path
1326 DF.IconPickFrame.customIcon = DF:CreateLabel (DF.IconPickFrame, "Icon Path:", DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
1327 DF.IconPickFrame.customIcon:SetPoint ("bottomleft", DF.IconPickFrame, "bottomleft", 12, 16)
1328
1329 DF.IconPickFrame.customIconEntry = DF:CreateTextEntry (DF.IconPickFrame, function()end, 200, 20, "CustomIconEntry", _, _, DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
1330 DF.IconPickFrame.customIconEntry:SetPoint ("left", DF.IconPickFrame.customIcon, "right", 2, 0)
1331
1332 DF.IconPickFrame.customIconEntry:SetHook ("OnTextChanged", function()
1333 DF.IconPickFrame.preview:SetPoint ("bottom", DF.IconPickFrame.customIconEntry.widget, "top", 0, 2)
1334 DF.IconPickFrame.preview.icon:SetTexture (DF.IconPickFrame.customIconEntry:GetText())
1335 DF.IconPickFrame.preview:Show()
1336 end)
1337
1338 DF.IconPickFrame.customIconEntry:SetHook ("OnEnter", function()
1339 DF.IconPickFrame.preview:SetPoint ("bottom", DF.IconPickFrame.customIconEntry.widget, "top", 0, 2)
1340 DF.IconPickFrame.preview.icon:SetTexture (DF.IconPickFrame.customIconEntry:GetText())
1341 DF.IconPickFrame.preview:Show()
1342 end)
1343
1276 --> close button 1344 --> close button
1277 local close_button = CreateFrame ("button", nil, DF.IconPickFrame, "UIPanelCloseButton") 1345 local close_button = CreateFrame ("button", nil, DF.IconPickFrame, "UIPanelCloseButton")
1278 close_button:SetWidth (32) 1346 close_button:SetWidth (32)
1279 close_button:SetHeight (32) 1347 close_button:SetHeight (32)
1280 close_button:SetPoint ("TOPRIGHT", DF.IconPickFrame, "TOPRIGHT", -8, -7) 1348 close_button:SetPoint ("TOPRIGHT", DF.IconPickFrame, "TOPRIGHT", -8, -7)
1281 close_button:SetFrameLevel (close_button:GetFrameLevel()+2) 1349 close_button:SetFrameLevel (close_button:GetFrameLevel()+2)
1350 close_button:SetAlpha (0) --just hide, it is used below
1351
1352 --> accept custom icon button
1353 local accept_custom_icon = function()
1354 local path = DF.IconPickFrame.customIconEntry:GetText()
1355
1356 DF:QuickDispatch (DF.IconPickFrame.callback, path, DF.IconPickFrame.param1, DF.IconPickFrame.param2)
1357
1358 if (DF.IconPickFrame.click_close) then
1359 close_button:Click()
1360 end
1361 end
1362
1363 DF.IconPickFrame.customIconAccept = DF:CreateButton (DF.IconPickFrame, accept_custom_icon, 82, 20, "Accept", nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
1364 DF.IconPickFrame.customIconAccept:SetPoint ("left", DF.IconPickFrame.customIconEntry, "right", 2, 0)
1365
1366 --fill with icons
1282 1367
1283 local MACRO_ICON_FILENAMES = {} 1368 local MACRO_ICON_FILENAMES = {}
1284 local SPELLNAMES_CACHE = {} 1369 local SPELLNAMES_CACHE = {}
1285 1370
1286 DF.IconPickFrame:SetScript ("OnShow", function() 1371 DF.IconPickFrame:SetScript ("OnShow", function()
1318 1403
1319 GetLooseMacroItemIcons (MACRO_ICON_FILENAMES) 1404 GetLooseMacroItemIcons (MACRO_ICON_FILENAMES)
1320 GetLooseMacroIcons (MACRO_ICON_FILENAMES) 1405 GetLooseMacroIcons (MACRO_ICON_FILENAMES)
1321 GetMacroIcons (MACRO_ICON_FILENAMES) 1406 GetMacroIcons (MACRO_ICON_FILENAMES)
1322 GetMacroItemIcons (MACRO_ICON_FILENAMES) 1407 GetMacroItemIcons (MACRO_ICON_FILENAMES)
1323 1408
1409 --reset the custom icon text entry
1410 DF.IconPickFrame.customIconEntry:SetText ("")
1411 --reset the search text entry
1412 DF.IconPickFrame.search:SetText ("")
1324 end) 1413 end)
1325 1414
1326 DF.IconPickFrame:SetScript ("OnHide", function() 1415 DF.IconPickFrame:SetScript ("OnHide", function()
1327 wipe (MACRO_ICON_FILENAMES) 1416 wipe (MACRO_ICON_FILENAMES)
1417 DF.IconPickFrame.preview:Hide()
1328 collectgarbage() 1418 collectgarbage()
1329 end) 1419 end)
1330 1420
1331 DF.IconPickFrame.buttons = {} 1421 DF.IconPickFrame.buttons = {}
1332 1422
1333 local OnClickFunction = function (self) 1423 local OnClickFunction = function (self)
1334 DF.IconPickFrame.callback (self.icon:GetTexture(), DF.IconPickFrame.param1, DF.IconPickFrame.param2) 1424
1425 DF:QuickDispatch (DF.IconPickFrame.callback, self.icon:GetTexture(), DF.IconPickFrame.param1, DF.IconPickFrame.param2)
1426
1335 if (DF.IconPickFrame.click_close) then 1427 if (DF.IconPickFrame.click_close) then
1336 close_button:Click() 1428 close_button:Click()
1337 end 1429 end
1338 end 1430 end
1339 1431
1360 newcheck:SetBackdrop (backdrop) 1452 newcheck:SetBackdrop (backdrop)
1361 1453
1362 newcheck:SetScript ("OnClick", OnClickFunction) 1454 newcheck:SetScript ("OnClick", OnClickFunction)
1363 newcheck.param1 = i+1 1455 newcheck.param1 = i+1
1364 1456
1365 newcheck:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12 + (i*30), -40) 1457 newcheck:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12 + (i*30), -60)
1366 newcheck:SetID (i+1) 1458 newcheck:SetID (i+1)
1367 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck 1459 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
1368 newcheck:SetScript ("OnEnter", onenter) 1460 newcheck:SetScript ("OnEnter", onenter)
1369 newcheck:SetScript ("OnLeave", onleave) 1461 newcheck:SetScript ("OnLeave", onleave)
1370 end 1462 end
1453 newcheck:SetScript ("OnEnter", onenter) 1545 newcheck:SetScript ("OnEnter", onenter)
1454 newcheck:SetScript ("OnLeave", onleave) 1546 newcheck:SetScript ("OnLeave", onleave)
1455 end 1547 end
1456 1548
1457 local scroll = CreateFrame ("ScrollFrame", "DetailsFrameworkIconPickFrameScroll", DF.IconPickFrame, "ListScrollFrameTemplate") 1549 local scroll = CreateFrame ("ScrollFrame", "DetailsFrameworkIconPickFrameScroll", DF.IconPickFrame, "ListScrollFrameTemplate")
1550 DF:ReskinSlider (scroll)
1458 1551
1459 local ChecksFrame_Update = function (self) 1552 local ChecksFrame_Update = function (self)
1460 1553
1461 local numMacroIcons = #MACRO_ICON_FILENAMES 1554 local numMacroIcons = #MACRO_ICON_FILENAMES
1462 local macroPopupIcon, macroPopupButton 1555 local macroPopupIcon, macroPopupButton
1525 FauxScrollFrame_Update (scroll, ceil ((shown or numMacroIcons) / 10) , 5, 20 ) 1618 FauxScrollFrame_Update (scroll, ceil ((shown or numMacroIcons) / 10) , 5, 20 )
1526 end 1619 end
1527 1620
1528 DF.IconPickFrame.updateFunc = ChecksFrame_Update 1621 DF.IconPickFrame.updateFunc = ChecksFrame_Update
1529 1622
1530 scroll:SetPoint ("topleft", DF.IconPickFrame, "topleft", -18, -37) 1623 scroll:SetPoint ("topleft", DF.IconPickFrame, "topleft", -18, -58)
1531 scroll:SetWidth (330) 1624 scroll:SetWidth (330)
1532 scroll:SetHeight (178) 1625 scroll:SetHeight (178)
1533 scroll:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (scroll, offset, 20, ChecksFrame_Update) end) 1626 scroll:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (scroll, offset, 20, ChecksFrame_Update) end)
1534 scroll.update = ChecksFrame_Update 1627 scroll.update = ChecksFrame_Update
1535 DF.IconPickFrameScroll = scroll 1628 DF.IconPickFrameScroll = scroll
1607 1700
1608 local SimplePanel_frame_backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true} 1701 local SimplePanel_frame_backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}
1609 local SimplePanel_frame_backdrop_color = {0, 0, 0, 0.9} 1702 local SimplePanel_frame_backdrop_color = {0, 0, 0, 0.9}
1610 local SimplePanel_frame_backdrop_border_color = {0, 0, 0, 1} 1703 local SimplePanel_frame_backdrop_border_color = {0, 0, 0, 1}
1611 1704
1705 --with_label was making the frame stay in place while its parent moves
1706 --the slider was anchoring to with_label and here here were anchoring the slider again
1612 function DF:CreateScaleBar (frame, config) 1707 function DF:CreateScaleBar (frame, config)
1613 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")) 1708 local scaleBar, text = 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", "ORANGE_FONT_TEMPLATE"))
1614 scaleBar:SetPoint ("right", frame.Close, "left", -26, 0) 1709 --scaleBar:SetPoint ("right", frame.Close, "left", -26, 0)
1710 text:SetPoint ("topleft", frame, "topleft", 12, -7)
1615 scaleBar:SetFrameLevel (DF.FRAMELEVEL_OVERLAY) 1711 scaleBar:SetFrameLevel (DF.FRAMELEVEL_OVERLAY)
1616 scaleBar.OnValueChanged = function (_, _, value) 1712 scaleBar.OnValueChanged = function (_, _, value)
1617 config.scale = value 1713 config.scale = value
1618 if (not scaleBar.IsValueChanging) then 1714 if (not scaleBar.IsValueChanging) then
1619 frame:SetScale (config.scale) 1715 frame:SetScale (config.scale)
1620 end 1716 end
1621 end 1717 end
1622 scaleBar:SetHook ("OnMouseUp", function() 1718 scaleBar:SetHook ("OnMouseUp", function()
1623 frame:SetScale (config.scale) 1719 frame:SetScale (config.scale)
1624 end) 1720 end)
1721
1722 scaleBar:SetAlpha (0.2)
1723
1724 return scaleBar
1625 end 1725 end
1626 1726
1627 local no_options = {} 1727 local no_options = {}
1628 function DF:CreateSimplePanel (parent, w, h, title, name, panel_options, db) 1728 function DF:CreateSimplePanel (parent, w, h, title, name, panel_options, db)
1629 1729
3529 tabButton:SetFrameLevel (220) 3629 tabButton:SetFrameLevel (220)
3530 tabButton.textsize = button_text_size 3630 tabButton.textsize = button_text_size
3531 tabButton.mainFrame = mainFrame 3631 tabButton.mainFrame = mainFrame
3532 DF.TabContainerFunctions.CreateUnderlineGlow (tabButton) 3632 DF.TabContainerFunctions.CreateUnderlineGlow (tabButton)
3533 3633
3634 local right_click_to_back
3534 if (i == 1) then 3635 if (i == 1) then
3535 local right_click_to_back = DF:CreateLabel (f, "right click to close", 10, "gray") 3636 right_click_to_back = DF:CreateLabel (f, "right click to close", 10, "gray")
3536 right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0) 3637 right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0)
3537 f.IsFrontPage = true 3638 f.IsFrontPage = true
3538 else 3639 else
3539 local right_click_to_back = DF:CreateLabel (f, "right click to go back to main menu", 10, "gray") 3640 right_click_to_back = DF:CreateLabel (f, "right click to go back to main menu", 10, "gray")
3540 right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0) 3641 right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0)
3642 end
3643
3644 if (options_table.hide_click_label) then
3645 right_click_to_back:Hide()
3541 end 3646 end
3542 3647
3543 f:SetScript ("OnMouseDown", DF.TabContainerFunctions.OnMouseDown) 3648 f:SetScript ("OnMouseDown", DF.TabContainerFunctions.OnMouseDown)
3544 f:SetScript ("OnMouseUp", DF.TabContainerFunctions.OnMouseUp) 3649 f:SetScript ("OnMouseUp", DF.TabContainerFunctions.OnMouseUp)
3545 3650
3605 if (not widget) then 3710 if (not widget) then
3606 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")) 3711 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"))
3607 widget:SetHook ("OnEnter", simple_list_box_onenter) 3712 widget:SetHook ("OnEnter", simple_list_box_onenter)
3608 widget:SetHook ("OnLeave", simple_list_box_onleave) 3713 widget:SetHook ("OnLeave", simple_list_box_onleave)
3609 widget.textcolor = self.options.textcolor 3714 widget.textcolor = self.options.textcolor
3715 widget.textsize = self.options.text_size
3716 widget.onleave_backdrop = self.options.backdrop_color
3717
3718 widget.XButton = DF:CreateButton (widget, function()end, 16, 16)
3719 widget.XButton:SetPoint ("topright", widget.widget, "topright")
3720 widget.XButton:SetIcon ([[Interface\BUTTONS\UI-Panel-MinimizeButton-Up]], 16, 16, "overlay", nil, nil, 0, -4, 0, false)
3721 widget.XButton.icon:SetDesaturated (true)
3722
3723 if (not self.options.show_x_button) then
3724 widget.XButton:Hide()
3725 end
3726
3610 tinsert (self.widgets, widget) 3727 tinsert (self.widgets, widget)
3611 end 3728 end
3612 self.nextWidget = self.nextWidget + 1 3729 self.nextWidget = self.nextWidget + 1
3613 return widget 3730 return widget
3614 end 3731 end
3618 local amt = 0 3735 local amt = 0
3619 for value, _ in pairs (self.list_table) do 3736 for value, _ in pairs (self.list_table) do
3620 local widget = self:GetOrCreateWidget() 3737 local widget = self:GetOrCreateWidget()
3621 widget:SetPoint ("topleft", self, "topleft", 1, -self.options.row_height * (self.nextWidget-2) - 4) 3738 widget:SetPoint ("topleft", self, "topleft", 1, -self.options.row_height * (self.nextWidget-2) - 4)
3622 widget:SetPoint ("topright", self, "topright", -1, -self.options.row_height * (self.nextWidget-2) - 4) 3739 widget:SetPoint ("topright", self, "topright", -1, -self.options.row_height * (self.nextWidget-2) - 4)
3740
3623 widget:SetClickFunction (self.func, value) 3741 widget:SetClickFunction (self.func, value)
3742
3743 if (self.options.show_x_button) then
3744 widget.XButton:SetClickFunction (self.options.x_button_func, value)
3745 widget.XButton.value = value
3746 widget.XButton:Show()
3747 else
3748 widget.XButton:Hide()
3749 end
3750
3624 widget.value = value 3751 widget.value = value
3625 3752
3626 if (self.options.icon) then 3753 if (self.options.icon) then
3627 if (type (self.options.icon) == "string" or type (self.options.icon) == "number") then 3754 if (type (self.options.icon) == "string" or type (self.options.icon) == "number") then
3628 widget:SetIcon (self.options.icon, self.options.row_height, self.options.row_height) 3755 local coords = type (self.options.iconcoords) == "table" and self.options.iconcoords or {0, 1, 0, 1}
3756 widget:SetIcon (self.options.icon, self.options.row_height - 2, self.options.row_height - 2, "overlay", coords)
3757
3629 elseif (type (self.options.icon) == "function") then 3758 elseif (type (self.options.icon) == "function") then
3630 local icon = self.options.icon (value) 3759 local icon = self.options.icon (value)
3631 if (icon) then 3760 if (icon) then
3632 widget:SetIcon (icon, self.options.row_height, self.options.row_height) 3761 local coords = type (self.options.iconcoords) == "table" and self.options.iconcoords or {0, 1, 0, 1}
3762 widget:SetIcon (icon, self.options.row_height - 2, self.options.row_height - 2, "overlay", coords)
3633 end 3763 end
3634 end 3764 end
3635 else 3765 else
3636 widget:SetIcon ("", self.options.row_height, self.options.row_height) 3766 widget:SetIcon ("", self.options.row_height, self.options.row_height)
3637 end 3767 end
3650 else 3780 else
3651 widget:SetText ("") 3781 widget:SetText ("")
3652 end 3782 end
3653 3783
3654 widget.value = value 3784 widget.value = value
3785
3786 local r, g, b, a = DF:ParseColors (self.options.backdrop_color)
3787 widget:SetBackdropColor (r, g, b, a)
3788
3655 widget:Show() 3789 widget:Show()
3656 amt = amt + 1 3790 amt = amt + 1
3657 end 3791 end
3658 if (amt == 0) then 3792 if (amt == 0) then
3659 self.EmptyLabel:Show() 3793 self.EmptyLabel:Show()
3667 height = 400, 3801 height = 400,
3668 row_height = 16, 3802 row_height = 16,
3669 width = 230, 3803 width = 230,
3670 icon = false, 3804 icon = false,
3671 text = "", 3805 text = "",
3806 text_size = 10,
3672 textcolor = "wheat", 3807 textcolor = "wheat",
3808
3809 backdrop_color = {1, 1, 1, .5},
3810 panel_border_color = {0, 0, 0, 0.5},
3811
3673 onenter = function (self, capsule) 3812 onenter = function (self, capsule)
3674 if (capsule) then 3813 if (capsule) then
3675 capsule.textcolor = "white" 3814 capsule.textcolor = "white"
3676 end 3815 end
3677 end, 3816 end,
3695 f.Refresh = simple_list_box_RefreshWidgets 3834 f.Refresh = simple_list_box_RefreshWidgets
3696 f.SetData = simple_list_box_SetData 3835 f.SetData = simple_list_box_SetData
3697 f.nextWidget = 1 3836 f.nextWidget = 1
3698 f.list_table = list_table 3837 f.list_table = list_table
3699 f.func = function (self, button, value) 3838 f.func = function (self, button, value)
3700 onclick (value) 3839 --onclick (value)
3840 DF:QuickDispatch (onclick, value)
3701 f:Refresh() 3841 f:Refresh()
3702 end 3842 end
3703 f.widgets = {} 3843 f.widgets = {}
3704 f:SetBackdrop (backdrop) 3844
3705 f:SetBackdropColor (0, 0, 0, 0.3) 3845 DF:ApplyStandardBackdrop (f)
3706 f:SetBackdropBorderColor (0, 0, 0, 0.5) 3846
3707 f.options = options or {} 3847 f.options = options or {}
3708 self.table.deploy (f.options, default_options) 3848 self.table.deploy (f.options, default_options)
3849
3850 if (f.options.x_button_func) then
3851 local original_X_function = f.options.x_button_func
3852 f.options.x_button_func = function (self, button, value)
3853 DF:QuickDispatch (original_X_function, value)
3854 f:Refresh()
3855 end
3856 end
3857
3858 f:SetBackdropBorderColor (unpack (f.options.panel_border_color))
3709 3859
3710 f:SetSize (f.options.width + 2, f.options.height) 3860 f:SetSize (f.options.width + 2, f.options.height)
3711 3861
3712 local name = DF:CreateLabel (f, title, 12, "silver") 3862 local name = DF:CreateLabel (f, title, 12, "silver")
3713 name:SetTemplate (DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) 3863 name:SetTemplate (DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
3896 end 4046 end
3897 end 4047 end
3898 4048
3899 function DF:CreateScrollBox (parent, name, refresh_func, data, width, height, line_amount, line_height, create_line_func, auto_amount, no_scroll) 4049 function DF:CreateScrollBox (parent, name, refresh_func, data, width, height, line_amount, line_height, create_line_func, auto_amount, no_scroll)
3900 local scroll = CreateFrame ("scrollframe", name, parent, "FauxScrollFrameTemplate") 4050 local scroll = CreateFrame ("scrollframe", name, parent, "FauxScrollFrameTemplate")
4051
4052 DF:ApplyStandardBackdrop (scroll)
3901 4053
3902 scroll:SetSize (width, height) 4054 scroll:SetSize (width, height)
3903 scroll.LineAmount = line_amount 4055 scroll.LineAmount = line_amount
3904 scroll.LineHeight = line_height 4056 scroll.LineHeight = line_height
3905 scroll.IsFauxScroll = true 4057 scroll.IsFauxScroll = true
3948 leftResizer:GetPushedTexture():SetTexCoord (1, 0, 0, 1) 4100 leftResizer:GetPushedTexture():SetTexCoord (1, 0, 0, 1)
3949 4101
3950 return leftResizer, rightResizer 4102 return leftResizer, rightResizer
3951 end 4103 end
3952 end 4104 end
4105
4106
4107 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4108 -- ~keybind
4109
4110
4111 --------------------------------
4112 --> keybind frame ~key
4113
4114
4115 local ignoredKeys = {
4116 ["LSHIFT"] = true,
4117 ["RSHIFT"] = true,
4118 ["LCTRL"] = true,
4119 ["RCTRL"] = true,
4120 ["LALT"] = true,
4121 ["RALT"] = true,
4122 ["UNKNOWN"] = true,
4123 }
4124
4125 local mouseKeys = {
4126 ["LeftButton"] = "type1",
4127 ["RightButton"] = "type2",
4128 ["MiddleButton"] = "type3",
4129 ["Button4"] = "type4",
4130 ["Button5"] = "type5",
4131 ["Button6"] = "type6",
4132 ["Button7"] = "type7",
4133 ["Button8"] = "type8",
4134 ["Button9"] = "type9",
4135 ["Button10"] = "type10",
4136 ["Button11"] = "type11",
4137 ["Button12"] = "type12",
4138 ["Button13"] = "type13",
4139 ["Button14"] = "type14",
4140 ["Button15"] = "type15",
4141 ["Button16"] = "type16",
4142 }
4143
4144 local keysToMouse = {
4145 ["type1"] = "LeftButton",
4146 ["type2"] = "RightButton",
4147 ["type3"] = "MiddleButton",
4148 ["type4"] = "Button4",
4149 ["type5"] = "Button5",
4150 ["type6"] = "Button6",
4151 ["type7"] = "Button7",
4152 ["type8"] = "Button8",
4153 ["type9"] = "Button9",
4154 ["type10"] = "Button10",
4155 ["type11"] = "Button11",
4156 ["type12"] = "Button12",
4157 ["type13"] = "Button13",
4158 ["type14"] = "Button14",
4159 ["type15"] = "Button15",
4160 ["type16"] = "Button16",
4161 }
4162
4163 local keybind_set_data = function (self, new_data_table)
4164 self.Data = new_data_table
4165 self.keybindScroll:UpdateScroll()
4166 end
4167
4168 function DF:CreateKeybindBox (parent, name, data, callback, width, height, line_amount, line_height)
4169
4170 local options_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")
4171 local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
4172 local options_switch_template = DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE")
4173 local options_slider_template = DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE")
4174 local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")
4175
4176 local SCROLL_ROLL_AMOUNT = line_amount
4177
4178 --keybind set frame
4179 local new_keybind_frame = CreateFrame ("frame", name, parent)
4180 new_keybind_frame:SetSize (width, height)
4181
4182 -- keybind scrollframe
4183 local keybindScroll = CreateFrame ("scrollframe", "$parentScrollFrame", new_keybind_frame, "FauxScrollFrameTemplate")
4184 keybindScroll:SetSize (1019, 348)
4185 keybindScroll.Frames = {}
4186 new_keybind_frame.keybindScroll = keybindScroll
4187
4188 --waiting the player to press a key
4189 new_keybind_frame.IsListening = false
4190
4191 --check for valid data table
4192 if (type (data) ~= "table") then
4193 print ("error: data must be a table. DF > CreateKeybindBox()")
4194 return
4195 end
4196
4197 if (not next (data)) then
4198 --> build data table for the character class
4199 local _, unitClass = UnitClass ("player")
4200 if (unitClass) then
4201 local specIds = DF:GetClassSpecIDs (unitClass)
4202 if (specIds) then
4203 for _, specId in ipairs (specIds) do
4204 data [specId] = {}
4205 end
4206 end
4207 end
4208 end
4209
4210 new_keybind_frame.Data = data
4211 new_keybind_frame.SetData = keybind_set_data
4212
4213 new_keybind_frame.EditingSpec = DF:GetCurrentSpec()
4214 new_keybind_frame.CurrentKeybindEditingSet = new_keybind_frame.Data [new_keybind_frame.EditingSpec]
4215
4216 local allSpecButtons = {}
4217 local switch_spec = function (self, button, specID)
4218 new_keybind_frame.EditingSpec = specID
4219 new_keybind_frame.CurrentKeybindEditingSet = new_keybind_frame.Data [specID]
4220
4221 for _, button in ipairs (allSpecButtons) do
4222 button.selectedTexture:Hide()
4223 end
4224 self.MyObject.selectedTexture:Show()
4225
4226 --feedback ao jogador uma vez que as keybinds podem ter o mesmo valor
4227 C_Timer.After (.04, function() new_keybind_frame:Hide() end)
4228 C_Timer.After (.06, function() new_keybind_frame:Show() end)
4229
4230 --atualiza a scroll
4231 keybindScroll:UpdateScroll()
4232 end
4233
4234 --choose which spec to use
4235 local spec1 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec1 Placeholder Text", 1, _, _, "SpecButton1", _, 0, options_button_template, options_text_template)
4236 local spec2 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec2 Placeholder Text", 1, _, _, "SpecButton2", _, 0, options_button_template, options_text_template)
4237 local spec3 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec3 Placeholder Text", 1, _, _, "SpecButton3", _, 0, options_button_template, options_text_template)
4238 local spec4 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec4 Placeholder Text", 1, _, _, "SpecButton4", _, 0, options_button_template, options_text_template)
4239
4240 --format the button label and icon with the spec information
4241 local className, class = UnitClass ("player")
4242 local i = 1
4243 local specIds = DF:GetClassSpecIDs (class)
4244
4245 for index, specId in ipairs (specIds) do
4246 local button = new_keybind_frame ["SpecButton" .. index]
4247 local spec_id, spec_name, spec_description, spec_icon, spec_background, spec_role, spec_class = GetSpecializationInfoByID (specId)
4248 button.text = spec_name
4249 button:SetClickFunction (switch_spec, specId)
4250 button:SetIcon (spec_icon)
4251 button.specID = specId
4252
4253 local selectedTexture = button:CreateTexture (nil, "background")
4254 selectedTexture:SetAllPoints()
4255 selectedTexture:SetColorTexture (1, 1, 1, 0.5)
4256 if (specId ~= new_keybind_frame.EditingSpec) then
4257 selectedTexture:Hide()
4258 end
4259 button.selectedTexture = selectedTexture
4260
4261 tinsert (allSpecButtons, button)
4262 i = i + 1
4263 end
4264
4265 local specsTitle = DF:CreateLabel (new_keybind_frame, "Config keys for spec:", 12, "silver")
4266 specsTitle:SetPoint ("topleft", new_keybind_frame, "topleft", 10, mainStartY)
4267
4268 keybindScroll:SetPoint ("topleft", specsTitle.widget, "bottomleft", 0, -120)
4269
4270 spec1:SetPoint ("topleft", specsTitle, "bottomleft", 0, -10)
4271 spec2:SetPoint ("topleft", specsTitle, "bottomleft", 0, -30)
4272 spec3:SetPoint ("topleft", specsTitle, "bottomleft", 0, -50)
4273 if (class == "DRUID") then
4274 spec4:SetPoint ("topleft", specsTitle, "bottomleft", 0, -70)
4275 end
4276
4277 local enter_the_key = CreateFrame ("frame", nil, new_keybind_frame)
4278 enter_the_key:SetFrameStrata ("tooltip")
4279 enter_the_key:SetSize (200, 60)
4280 enter_the_key:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1})
4281 enter_the_key:SetBackdropColor (0, 0, 0, 1)
4282 enter_the_key:SetBackdropBorderColor (1, 1, 1, 1)
4283 enter_the_key.text = DF:CreateLabel (enter_the_key, "- Press a keyboard key to bind.\n- Click to bind a mouse button.\n- Press escape to cancel.", 11, "orange")
4284 enter_the_key.text:SetPoint ("center", enter_the_key, "center")
4285 enter_the_key:Hide()
4286
4287 local registerKeybind = function (self, key)
4288 if (ignoredKeys [key]) then
4289 return
4290 end
4291 if (key == "ESCAPE") then
4292 enter_the_key:Hide()
4293 new_keybind_frame.IsListening = false
4294 new_keybind_frame:SetScript ("OnKeyDown", nil)
4295 return
4296 end
4297
4298 local bind = (IsShiftKeyDown() and "SHIFT-" or "") .. (IsControlKeyDown() and "CTRL-" or "") .. (IsAltKeyDown() and "ALT-" or "")
4299 bind = bind .. key
4300
4301 --adiciona para a tabela de keybinds
4302 local keybind = new_keybind_frame.CurrentKeybindEditingSet [self.keybindIndex]
4303 keybind.key = bind
4304
4305 new_keybind_frame.IsListening = false
4306 new_keybind_frame:SetScript ("OnKeyDown", nil)
4307
4308 enter_the_key:Hide()
4309 new_keybind_frame.keybindScroll:UpdateScroll()
4310
4311 DF:QuickDispatch (callback)
4312 end
4313
4314 local set_keybind_key = function (self, button, keybindIndex)
4315 if (new_keybind_frame.IsListening) then
4316 key = mouseKeys [button] or button
4317 return registerKeybind (new_keybind_frame, key)
4318 end
4319 new_keybind_frame.IsListening = true
4320 new_keybind_frame.keybindIndex = keybindIndex
4321 new_keybind_frame:SetScript ("OnKeyDown", registerKeybind)
4322
4323 enter_the_key:Show()
4324 enter_the_key:SetPoint ("bottom", self, "top")
4325 end
4326
4327 local new_key_bind = function (self, button, specID)
4328 tinsert (new_keybind_frame.CurrentKeybindEditingSet, {key = "-none-", action = "_target", actiontext = ""})
4329 FauxScrollFrame_SetOffset (new_keybind_frame.keybindScroll, max (#new_keybind_frame.CurrentKeybindEditingSet-SCROLL_ROLL_AMOUNT, 0))
4330 new_keybind_frame.keybindScroll:UpdateScroll()
4331 end
4332
4333 local set_action_text = function (keybindIndex, _, text)
4334 local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex]
4335 keybind.actiontext = text
4336 DF:QuickDispatch (callback)
4337 end
4338
4339 local set_action_on_espace_press = function (textentry, capsule)
4340 capsule = capsule or textentry.MyObject
4341 local keybind = new_keybind_frame.CurrentKeybindEditingSet [capsule.CurIndex]
4342 textentry:SetText (keybind.actiontext)
4343 DF:QuickDispatch (callback)
4344 end
4345
4346 local lock_textentry = {
4347 ["_target"] = true,
4348 ["_taunt"] = true,
4349 ["_interrupt"] = true,
4350 ["_dispel"] = true,
4351 ["_spell"] = false,
4352 ["_macro"] = false,
4353 }
4354
4355 local change_key_action = function (self, keybindIndex, value)
4356 local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex]
4357 keybind.action = value
4358 new_keybind_frame.keybindScroll:UpdateScroll()
4359 DF:QuickDispatch (callback)
4360 end
4361 local fill_action_dropdown = function()
4362
4363 local locClass, class = UnitClass ("player")
4364
4365 local taunt = ""
4366 local interrupt = ""
4367 local dispel = ""
4368
4369 if (type (dispel) == "table") then
4370 local dispelString = "\n"
4371 for specID, spellid in pairs (dispel) do
4372 local specid, specName = GetSpecializationInfoByID (specID)
4373 local spellName = GetSpellInfo (spellid)
4374 dispelString = dispelString .. "|cFFE5E5E5" .. specName .. "|r: |cFFFFFFFF" .. spellName .. "\n"
4375 end
4376 dispel = dispelString
4377 else
4378 dispel = ""
4379 end
4380
4381 return {
4382 --{value = "_target", label = "Target", onclick = change_key_action, desc = "Target the unit"},
4383 --{value = "_taunt", label = "Taunt", onclick = change_key_action, desc = "Cast the taunt spell for your class\n\n|cFFFFFFFFSpell: " .. taunt},
4384 --{value = "_interrupt", label = "Interrupt", onclick = change_key_action, desc = "Cast the interrupt spell for your class\n\n|cFFFFFFFFSpell: " .. interrupt},
4385 --{value = "_dispel", label = "Dispel", onclick = change_key_action, desc = "Cast the interrupt spell for your class\n\n|cFFFFFFFFSpell: " .. dispel},
4386 {value = "_spell", label = "Cast Spell", onclick = change_key_action, desc = "Type the spell name in the text box"},
4387 {value = "_macro", label = "Run Macro", onclick = change_key_action, desc = "Type your macro in the text box"},
4388 }
4389 end
4390
4391 local copy_keybind = function (self, button, keybindIndex)
4392 local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex]
4393 for specID, t in pairs (new_keybind_frame.Data) do
4394 if (specID ~= new_keybind_frame.EditingSpec) then
4395 local key = CopyTable (keybind)
4396 local specid, specName = GetSpecializationInfoByID (specID)
4397 tinsert (new_keybind_frame.Data [specID], key)
4398 DF:Msg ("Keybind copied to " .. specName)
4399 end
4400 end
4401 DF:QuickDispatch (callback)
4402 end
4403
4404 local delete_keybind = function (self, button, keybindIndex)
4405 tremove (new_keybind_frame.CurrentKeybindEditingSet, keybindIndex)
4406 new_keybind_frame.keybindScroll:UpdateScroll()
4407 DF:QuickDispatch (callback)
4408 end
4409
4410 local newTitle = DF:CreateLabel (new_keybind_frame, "Create a new Keybind:", 12, "silver")
4411 newTitle:SetPoint ("topleft", new_keybind_frame, "topleft", 200, mainStartY)
4412 local createNewKeybind = DF:CreateButton (new_keybind_frame, new_key_bind, 160, 20, "New Key Bind", 1, _, _, "NewKeybindButton", _, 0, options_button_template, options_text_template)
4413 createNewKeybind:SetPoint ("topleft", newTitle, "bottomleft", 0, -10)
4414 --createNewKeybind:SetIcon ([[Interface\Buttons\UI-GuildButton-PublicNote-Up]])
4415
4416 local update_keybind_list = function (self)
4417
4418 local keybinds = new_keybind_frame.CurrentKeybindEditingSet
4419 FauxScrollFrame_Update (self, #keybinds, SCROLL_ROLL_AMOUNT, 21)
4420 local offset = FauxScrollFrame_GetOffset (self)
4421
4422 for i = 1, SCROLL_ROLL_AMOUNT do
4423 local index = i + offset
4424 local f = self.Frames [i]
4425 local data = keybinds [index]
4426
4427 if (data) then
4428 --index
4429 f.Index.text = index
4430 --keybind
4431 local keyBindText = keysToMouse [data.key] or data.key
4432
4433 keyBindText = keyBindText:gsub ("type1", "LeftButton")
4434 keyBindText = keyBindText:gsub ("type2", "RightButton")
4435 keyBindText = keyBindText:gsub ("type3", "MiddleButton")
4436
4437 f.KeyBind.text = keyBindText
4438 f.KeyBind:SetClickFunction (set_keybind_key, index, nil, "left")
4439 f.KeyBind:SetClickFunction (set_keybind_key, index, nil, "right")
4440 --action
4441 f.ActionDrop:SetFixedParameter (index)
4442 f.ActionDrop:Select (data.action)
4443 --action text
4444 f.ActionText.text = data.actiontext
4445 f.ActionText:SetEnterFunction (set_action_text, index)
4446 f.ActionText.CurIndex = index
4447
4448 if (lock_textentry [data.action]) then
4449 f.ActionText:Disable()
4450 else
4451 f.ActionText:Enable()
4452 end
4453
4454 --copy
4455 f.Copy:SetClickFunction (copy_keybind, index)
4456 --delete
4457 f.Delete:SetClickFunction (delete_keybind, index)
4458
4459 f:Show()
4460 else
4461 f:Hide()
4462 end
4463 end
4464
4465 self:Show()
4466 end
4467
4468
4469
4470 keybindScroll:SetScript ("OnVerticalScroll", function (self, offset)
4471 FauxScrollFrame_OnVerticalScroll (self, offset, 21, update_keybind_list)
4472 end)
4473 keybindScroll.UpdateScroll = update_keybind_list
4474
4475 local backdropColor = {.3, .3, .3, .3}
4476 local backdropColorOnEnter = {.6, .6, .6, .6}
4477 local on_enter = function (self)
4478 self:SetBackdropColor (unpack (backdropColorOnEnter))
4479 end
4480 local on_leave = function (self)
4481 self:SetBackdropColor (unpack (backdropColor))
4482 end
4483
4484 local font = "GameFontHighlightSmall"
4485
4486 for i = 1, SCROLL_ROLL_AMOUNT do
4487 local f = CreateFrame ("frame", "$KeyBindFrame" .. i, keybindScroll)
4488 f:SetSize (1009, 20)
4489 f:SetPoint ("topleft", keybindScroll, "topleft", 0, -(i-1)*29)
4490 f:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
4491 f:SetBackdropColor (unpack (backdropColor))
4492 f:SetScript ("OnEnter", on_enter)
4493 f:SetScript ("OnLeave", on_leave)
4494 tinsert (keybindScroll.Frames, f)
4495
4496 f.Index = DF:CreateLabel (f, "1")
4497 f.KeyBind = DF:CreateButton (f, set_key_bind, 100, 20, "", _, _, _, "SetNewKeybindButton", _, 0, options_button_template, options_text_template)
4498 f.ActionDrop = DF:CreateDropDown (f, fill_action_dropdown, 0, 120, 20, "ActionDropdown", _, options_dropdown_template)
4499 f.ActionText = DF:CreateTextEntry (f, function()end, 660, 20, "TextBox", _, _, options_dropdown_template)
4500 f.Copy = DF:CreateButton (f, copy_keybind, 20, 20, "", _, _, _, "CopyKeybindButton", _, 0, options_button_template, options_text_template)
4501 f.Delete = DF:CreateButton (f, delete_keybind, 16, 20, "", _, _, _, "DeleteKeybindButton", _, 2, options_button_template, options_text_template)
4502
4503 f.Index:SetPoint ("left", f, "left", 10, 0)
4504 f.KeyBind:SetPoint ("left", f, "left", 43, 0)
4505 f.ActionDrop:SetPoint ("left", f, "left", 150, 0)
4506 f.ActionText:SetPoint ("left", f, "left", 276, 0)
4507 f.Copy:SetPoint ("left", f, "left", 950, 0)
4508 f.Delete:SetPoint ("left", f, "left", 990, 0)
4509
4510 f.Copy:SetIcon ([[Interface\Buttons\UI-GuildButton-PublicNote-Up]], nil, nil, nil, nil, nil, nil, 4)
4511 f.Delete:SetIcon ([[Interface\Buttons\UI-StopButton]], nil, nil, nil, nil, nil, nil, 4)
4512
4513 f.Copy.tooltip = "copy this keybind to other specs"
4514 f.Delete.tooltip = "erase this keybind"
4515
4516 --editbox
4517 f.ActionText:SetJustifyH ("left")
4518 f.ActionText:SetHook ("OnEscapePressed", set_action_on_espace_press)
4519 f.ActionText:SetHook ("OnEditFocusGained", function()
4520 local playerSpells = {}
4521 local tab, tabTex, offset, numSpells = GetSpellTabInfo (2)
4522 for i = 1, numSpells do
4523 local index = offset + i
4524 local spellType, spellId = GetSpellBookItemInfo (index, "player")
4525 if (spellType == "SPELL") then
4526 local spellName = GetSpellInfo (spellId)
4527 tinsert (playerSpells, spellName)
4528 end
4529 end
4530 f.ActionText.WordList = playerSpells
4531 end)
4532
4533 f.ActionText:SetAsAutoComplete ("WordList")
4534 end
4535
4536 local header = CreateFrame ("frame", "$parentOptionsPanelFrameHeader", keybindScroll)
4537 header:SetPoint ("bottomleft", keybindScroll, "topleft", 0, 2)
4538 header:SetPoint ("bottomright", keybindScroll, "topright", 0, 2)
4539 header:SetHeight (16)
4540
4541 header.Index = DF:CreateLabel (header, "Index", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
4542 header.Key = DF:CreateLabel (header, "Key", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
4543 header.Action = DF:CreateLabel (header, "Action", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
4544 header.Macro = DF:CreateLabel (header, "Spell Name / Macro", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
4545 header.Copy = DF:CreateLabel (header, "Copy", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
4546 header.Delete = DF:CreateLabel (header, "Delete", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
4547
4548 header.Index:SetPoint ("left", header, "left", 10, 0)
4549 header.Key:SetPoint ("left", header, "left", 43, 0)
4550 header.Action:SetPoint ("left", header, "left", 150, 0)
4551 header.Macro:SetPoint ("left", header, "left", 276, 0)
4552 header.Copy:SetPoint ("left", header, "left", 950, 0)
4553 header.Delete:SetPoint ("left", header, "left", 990, 0)
4554
4555 new_keybind_frame:SetScript ("OnShow", function()
4556
4557 --new_keybind_frame.EditingSpec = EnemyGrid.CurrentSpec
4558 --new_keybind_frame.CurrentKeybindEditingSet = EnemyGrid.CurrentKeybindSet
4559
4560 for _, button in ipairs (allSpecButtons) do
4561 if (new_keybind_frame.EditingSpec ~= button.specID) then
4562 button.selectedTexture:Hide()
4563 else
4564 button.selectedTexture:Show()
4565 end
4566 end
4567
4568 keybindScroll:UpdateScroll()
4569 end)
4570
4571 new_keybind_frame:SetScript ("OnHide", function()
4572 if (new_keybind_frame.IsListening) then
4573 new_keybind_frame.IsListening = false
4574 new_keybind_frame:SetScript ("OnKeyDown", nil)
4575 end
4576 end)
4577
4578 return new_keybind_frame
4579 end
4580
4581 function DF:BuildKeybindFunctions (data, prefix)
4582
4583 --~keybind
4584 local classLoc, class = UnitClass ("player")
4585 local bindingList = data
4586
4587 local bindString = "self:ClearBindings();"
4588 local bindKeyBindTypeFunc = [[local unitFrame = ...;]]
4589 local bindMacroTextFunc = [[local unitFrame = ...;]]
4590 local isMouseBinding
4591
4592 for i = 1, #bindingList do
4593 local bind = bindingList [i]
4594 local bindType
4595
4596 --which button to press
4597 if (bind.key:find ("type")) then
4598 local keyNumber = tonumber (bind.key:match ("%d"))
4599 bindType = keyNumber
4600 isMouseBinding = true
4601 else
4602 bindType = prefix .. "" .. i
4603 bindString = bindString .. "self:SetBindingClick (0, '" .. bind.key .. "', self:GetName(), '" .. bindType .. "');"
4604 bindType = "-" .. prefix .. "" .. i
4605 isMouseBinding = nil
4606 end
4607
4608 --keybind type
4609 local shift, alt, ctrl = bind.key:match ("SHIFT"), bind.key:match ("ALT"), bind.key:match ("CTRL")
4610 local CommandKeys = alt and alt .. "-" or ""
4611 CommandKeys = ctrl and CommandKeys .. ctrl .. "-" or CommandKeys
4612 CommandKeys = shift and CommandKeys .. shift .. "-" or CommandKeys
4613
4614 local keyBindType
4615 if (isMouseBinding) then
4616 keyBindType = [[unitFrame:SetAttribute ("@COMMANDtype@BINDTYPE", "macro");]]
4617 else
4618 keyBindType = [[unitFrame:SetAttribute ("type@BINDTYPE", "macro");]]
4619 end
4620
4621 keyBindType = keyBindType:gsub ("@BINDTYPE", bindType)
4622 keyBindType = keyBindType:gsub ("@COMMAND", CommandKeys)
4623 bindKeyBindTypeFunc = bindKeyBindTypeFunc .. keyBindType
4624
4625 --spell or macro
4626 if (bind.action == "_spell") then
4627 local macroTextLine
4628 if (isMouseBinding) then
4629 macroTextLine = [[unitFrame:SetAttribute ("@COMMANDmacrotext@BINDTYPE", "/cast [@mouseover] @SPELL");]]
4630 else
4631 macroTextLine = [[unitFrame:SetAttribute ("macrotext@BINDTYPE", "/cast [@mouseover] @SPELL");]]
4632 end
4633 macroTextLine = macroTextLine:gsub ("@BINDTYPE", bindType)
4634 macroTextLine = macroTextLine:gsub ("@SPELL", bind.actiontext)
4635 macroTextLine = macroTextLine:gsub ("@COMMAND", CommandKeys)
4636 bindMacroTextFunc = bindMacroTextFunc .. macroTextLine
4637
4638 elseif (bind.action == "_macro") then
4639 local macroTextLine
4640 if (isMouseBinding) then
4641 macroTextLine = [[unitFrame:SetAttribute ("@COMMANDmacrotext@BINDTYPE", "@MACRO");]]
4642 else
4643 macroTextLine = [[unitFrame:SetAttribute ("macrotext@BINDTYPE", "@MACRO");]]
4644 end
4645 macroTextLine = macroTextLine:gsub ("@BINDTYPE", bindType)
4646 macroTextLine = macroTextLine:gsub ("@MACRO", bind.actiontext)
4647 macroTextLine = macroTextLine:gsub ("@COMMAND", CommandKeys)
4648 bindMacroTextFunc = bindMacroTextFunc .. macroTextLine
4649
4650 end
4651 end
4652
4653 --~key
4654 local bindTypeFuncLoaded = loadstring (bindKeyBindTypeFunc)
4655 local bindMacroFuncLoaded = loadstring (bindMacroTextFunc)
4656
4657 if (not bindMacroFuncLoaded or not bindTypeFuncLoaded) then
4658 return
4659 end
4660
4661 return bindString, bindTypeFuncLoaded, bindMacroFuncLoaded
4662 end
4663
4664
4665 function DF:SetKeybindsOnProtectedFrame (frame, bind_string, bind_type_func, bind_macro_func)
4666
4667 bind_type_func (frame)
4668 bind_macro_func (frame)
4669 frame:SetAttribute ("_onenter", bind_string)
4670
4671 end
4672
4673 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4674 -- ~standard backdrop
4675
4676 function DF:ApplyStandardBackdrop (f, darkTheme, alphaScale)
4677 alphaScale = alphaScale or 1.0
4678
4679 if (darkTheme) then
4680 f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Cooldown\cooldown2]], tileSize = 32, tile = true})
4681 f:SetBackdropBorderColor (0, 0, 0, 1)
4682 f:SetBackdropColor (.54, .54, .54, .54 * alphaScale)
4683 else
4684 f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
4685 f:SetBackdropBorderColor (0, 0, 0, 1)
4686 f:SetBackdropColor (0, 0, 0, 0.2 * alphaScale)
4687 end
4688
4689 if (not f.__background) then
4690 f.__background = f:CreateTexture (nil, "background")
4691 end
4692
4693 f.__background:SetColorTexture (0.2317647, 0.2317647, 0.2317647)
4694 f.__background:SetVertexColor (0.27, 0.27, 0.27)
4695 f.__background:SetAlpha (0.8 * alphaScale)
4696 f.__background:SetVertTile (true)
4697 f.__background:SetHorizTile (true)
4698 f.__background:SetAllPoints()
4699 end
4700
4701 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4702 -- ~title bar
4703
4704 DF.TitleFunctions = {
4705
4706 SetTitle = function (self, titleText, titleColor, font, size)
4707 self.TitleLabel:SetText (titleText or self.TitleLabel:GetText())
4708
4709 if (titleColor) then
4710 local r, g, b, a = DF:ParseColors (titleColor)
4711 self.TitleLabel:SetTextColor (r, g, b, a)
4712 end
4713
4714 if (font) then
4715 DF:SetFontFace (self.TitleLabel, font)
4716 end
4717
4718 if (size) then
4719 DF:SetFontSize (self.TitleLabel, size)
4720 end
4721 end
4722
4723
4724 }
4725
4726 function DF:CreateTitleBar (f, titleText)
4727
4728 local titleBar = CreateFrame ("frame", f:GetName() and f:GetName() .. "TitleBar" or nil, f)
4729 titleBar:SetPoint ("topleft", f, "topleft", 2, -3)
4730 titleBar:SetPoint ("topright", f, "topright", -2, -3)
4731 titleBar:SetHeight (20)
4732 titleBar:SetBackdrop (SimplePanel_frame_backdrop) --it's an upload from this file
4733 titleBar:SetBackdropColor (.2, .2, .2, 1)
4734 titleBar:SetBackdropBorderColor (0, 0, 0, 1)
4735
4736 local closeButton = CreateFrame ("button", titleBar:GetName() and titleBar:GetName() .. "CloseButton" or nil, titleBar)
4737 closeButton:SetSize (16, 16)
4738 closeButton:SetNormalTexture (DF.folder .. "icons")
4739 closeButton:SetHighlightTexture (DF.folder .. "icons")
4740 closeButton:SetPushedTexture (DF.folder .. "icons")
4741 closeButton:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1)
4742 closeButton:GetHighlightTexture():SetTexCoord (0, 16/128, 0, 1)
4743 closeButton:GetPushedTexture():SetTexCoord (0, 16/128, 0, 1)
4744 closeButton:SetAlpha (0.7)
4745 closeButton:SetScript ("OnClick", simple_panel_close_click) --upvalue from this file
4746
4747 local titleLabel = titleBar:CreateFontString (titleBar:GetName() and titleBar:GetName() .. "TitleText" or nil, "overlay", "GameFontNormal")
4748 titleLabel:SetTextColor (.8, .8, .8, 1)
4749 titleLabel:SetText (titleText or "")
4750
4751 --anchors
4752 closeButton:SetPoint ("right", titleBar, "right", -2, 0)
4753 titleLabel:SetPoint ("center", titleBar, "center")
4754
4755 --members
4756 f.TitleBar = titleBar
4757 f.CloseButton = closeButton
4758 f.TitleLabel = titleLabel
4759
4760 DF:Mixin (f, DF.TitleFunctions)
4761
4762 return titleBar
4763 end
4764
4765
4766 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4767 -- ~icon row
4768
4769 DF.IconRowFunctions = {
4770
4771 GetIcon = function (self)
4772 local iconFrame = self.IconPool [self.NextIcon]
4773
4774 if (not iconFrame) then
4775 local newIconFrame = CreateFrame ("cooldown", "$parentIconCooldown" .. self.NextIcon, self, "CooldownFrameTemplate")
4776 newIconFrame:SetSize (self.options.icon_width, self.options.icon_height)
4777
4778 newIconFrame.Texture = newIconFrame:CreateTexture (nil, "background")
4779 newIconFrame.Texture:SetAllPoints()
4780
4781 newIconFrame.Text = newIconFrame:CreateFontString (nil, "overlay", "GameFontNormal")
4782 newIconFrame.Text:SetPoint ("center")
4783 newIconFrame.Text:Hide()
4784
4785 newIconFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1})
4786 newIconFrame:SetBackdropBorderColor (0, 0, 0, 0)
4787 newIconFrame:EnableMouse (false)
4788
4789 self.IconPool [self.NextIcon] = newIconFrame
4790 iconFrame = newIconFrame
4791 end
4792
4793 iconFrame:ClearAllPoints()
4794
4795 local anchor = self.options.anchor
4796 local anchorTo = self.NextIcon == 1 and self or self.IconPool [self.NextIcon - 1]
4797 local xPadding = self.NextIcon == 1 and self.options.left_padding or self.options.icon_padding
4798 local growDirection = self.options.grow_direction
4799
4800 if (growDirection == 1) then --grow to right
4801 if (self.NextIcon == 1) then
4802 iconFrame:SetPoint ("left", anchorTo, "left", xPadding, 0)
4803 else
4804 iconFrame:SetPoint ("left", anchorTo, "right", xPadding, 0)
4805 end
4806
4807 elseif (growDirection == 2) then --grow to left
4808 if (self.NextIcon == 1) then
4809 iconFrame:SetPoint ("right", anchorTo, "right", xPadding, 0)
4810 else
4811 iconFrame:SetPoint ("right", anchorTo, "left", xPadding, 0)
4812 end
4813
4814 end
4815
4816 DF:SetFontColor (iconFrame.Text, self.options.text_color)
4817
4818 self.NextIcon = self.NextIcon + 1
4819 return iconFrame
4820 end,
4821
4822 SetIcon = function (self, spellId, borderColor, startTime, duration)
4823 local spellName, _, spellIcon = GetSpellInfo (spellId)
4824
4825 if (spellIcon) then
4826 local iconFrame = self:GetIcon()
4827 iconFrame.Texture:SetTexture (spellIcon)
4828 iconFrame.Texture:SetTexCoord (unpack (self.options.texcoord))
4829
4830 if (borderColor) then
4831 iconFrame:SetBackdropBorderColor (Plater:ParseColors (borderColor))
4832 else
4833 iconFrame:SetBackdropBorderColor (0, 0, 0 ,0)
4834 end
4835
4836 if (startTime) then
4837 CooldownFrame_Set (iconFrame, startTime, duration, true, true)
4838
4839 if (self.options.show_text) then
4840 iconFrame.Text:Show()
4841 iconFrame.Text:SetText (floor (startTime + duration - GetTime()))
4842 else
4843 iconFrame.Text:Hide()
4844 end
4845 else
4846 iconFrame.Text:Hide()
4847 end
4848
4849 iconFrame:Show()
4850
4851 --> update the size of the frame
4852 self:SetWidth ((self.options.left_padding * 2) + (self.options.icon_padding * (self.NextIcon-2)) + (self.options.icon_width * (self.NextIcon - 1)))
4853
4854 --> show the frame
4855 self:Show()
4856
4857 return iconFrame
4858 end
4859 end,
4860
4861 ClearIcons = function (self)
4862 for i = 1, self.NextIcon -1 do
4863 self.IconPool [i]:Hide()
4864 end
4865 self.NextIcon = 1
4866 self:Hide()
4867 end,
4868
4869 GetIconGrowDirection = function (self)
4870 local side = self.options.anchor.side
4871
4872 if (side == 1) then
4873 return 1
4874 elseif (side == 2) then
4875 return 2
4876 elseif (side == 3) then
4877 return 1
4878 elseif (side == 4) then
4879 return 1
4880 elseif (side == 5) then
4881 return 2
4882 elseif (side == 6) then
4883 return 1
4884 elseif (side == 7) then
4885 return 2
4886 elseif (side == 8) then
4887 return 1
4888 elseif (side == 9) then
4889 return 1
4890 elseif (side == 10) then
4891 return 1
4892 elseif (side == 11) then
4893 return 2
4894 elseif (side == 12) then
4895 return 1
4896 elseif (side == 13) then
4897 return 1
4898 end
4899 end
4900 }
4901
4902 local default_icon_row_options = {
4903 icon_width = 20,
4904 icon_height = 20,
4905 texcoord = {.1, .9, .1, .9},
4906 show_text = true,
4907 text_color = {1, 1, 1, 1},
4908 left_padding = 2, --distance between right and left
4909 top_padding = 2, --distance between top and bottom
4910 icon_padding = 2, --distance between each icon
4911 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
4912 backdrop_color = {0, 0, 0, 0.5},
4913 backdrop_border_color = {0, 0, 0, 1},
4914 anchor = {side = 6, x = 2, y = 0},
4915 grow_direction = 1, --1 = to right 2 = to left
4916 }
4917
4918 function DF:CreateIconRow (parent, name, options)
4919 local f = CreateFrame ("frame", name, parent)
4920 f.IconPool = {}
4921 f.NextIcon = 1
4922
4923 DF:Mixin (f, DF.IconRowFunctions)
4924 DF:Mixin (f, DF.OptionsFunctions)
4925
4926 f:BuildOptionsTable (default_icon_row_options, options)
4927
4928 f:SetSize (f.options.icon_width, f.options.icon_height + (f.options.top_padding * 2))
4929 f:SetBackdrop (f.options.backdrop)
4930 f:SetBackdropColor (unpack (f.options.backdrop_color))
4931 f:SetBackdropBorderColor (unpack (f.options.backdrop_border_color))
4932
4933 return f
4934 end