Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 10 | Seerah-7 | --[[panelData = { |
2 | Seerah-7 | type = "panel", |
|
3 | Seerah-7 | name = "Window Title", |
|
4 | 29 | Seerah-7 | displayName = "My Longer Window Title", --(optional) (can be useful for long addon names or if you want to colorize it) |
5 | Seerah-7 | author = "Seerah", --(optional) |
|
6 | Seerah-7 | version = "2.0", --(optional) |
|
7 | 32 | Seerah-7 | slashCommand = "/myaddon", --(optional) will register a keybind to open to this panel (don't forget to include the slash!) |
8 | 10 | Seerah-7 | registerForRefresh = true, --boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown) |
9 | Seerah-7 | registerForDefaults = true, --boolean (optional) (will set all options controls back to default values) |
|
10 | 27 | Seerah-7 | resetFunc = function() print("defaults reset") end, --(optional) custom function to run after settings are reset to defaults |
11 | 10 | Seerah-7 | } ]] |
12 | Seerah-7 | ||
13 | Seerah-7 | ||
14 | 32 | Seerah-7 | local widgetVersion = 2 |
15 | 10 | Seerah-7 | local LAM = LibStub("LibAddonMenu-2.0") |
16 | Seerah-7 | if not LAM:RegisterWidget("panel", widgetVersion) then return end |
|
17 | Seerah-7 | ||
18 | Seerah-7 | local wm = WINDOW_MANAGER |
|
19 | Seerah-7 | local cm = CALLBACK_MANAGER |
|
20 | Seerah-7 | ||
21 | Seerah-7 | local function RefreshPanel(control) |
|
22 | 14 | Seerah-7 | local panel = control.panel or control --callback can be fired by a single control or by the panel showing |
23 | 10 | Seerah-7 | local panelControls = panel.controlsToRefresh |
24 | Seerah-7 | ||
25 | Seerah-7 | for i = 1, #panelControls do |
|
26 | Seerah-7 | local updateControl = panelControls[i] |
|
27 | Seerah-7 | if updateControl == control then return end |
|
28 | Seerah-7 | ||
29 | Seerah-7 | if updateControl.UpdateValue then |
|
30 | Seerah-7 | updateControl:UpdateValue() |
|
31 | Seerah-7 | end |
|
32 | Seerah-7 | if updateControl.UpdateDisabled then |
|
33 | Seerah-7 | updateControl:UpdateDisabled() |
|
34 | Seerah-7 | end |
|
35 | Seerah-7 | end |
|
36 | Seerah-7 | end |
|
37 | Seerah-7 | ||
38 | 27 | Seerah-7 | local function ForceDefaults(panel) |
39 | 25 | Seerah-7 | local panelControls = panel.controlsToRefresh |
40 | 10 | Seerah-7 | |
41 | Seerah-7 | for i = 1, #panelControls do |
|
42 | Seerah-7 | local updateControl = panelControls[i] |
|
43 | 27 | Seerah-7 | if updateControl.UpdateValue and updateControl.data.default ~= nil then |
44 | 10 | Seerah-7 | updateControl:UpdateValue(true) |
45 | Seerah-7 | end |
|
46 | Seerah-7 | end |
|
47 | 27 | Seerah-7 | |
48 | Seerah-7 | if panel.data.resetFunc then |
|
49 | Seerah-7 | panel.data.resetFunc() |
|
50 | Seerah-7 | end |
|
51 | 10 | Seerah-7 | end |
52 | 20 | Seerah-7 | ESO_Dialogs["LAM_DEFAULTS"] = { |
53 | Seerah-7 | title = { |
|
54 | Seerah-7 | text = "Reset To Defaults", |
|
55 | Seerah-7 | }, |
|
56 | Seerah-7 | mainText = { |
|
57 | Seerah-7 | text = "Reset this addon's settings to their default values?", |
|
58 | Seerah-7 | align = TEXT_ALIGN_CENTER, |
|
59 | Seerah-7 | }, |
|
60 | Seerah-7 | buttons = { |
|
61 | Seerah-7 | [1] = { |
|
62 | 27 | Seerah-7 | text = SI_OPTIONS_RESET, |
63 | Seerah-7 | callback = function(dialog) ForceDefaults(dialog.data[1]) end, |
|
64 | 20 | Seerah-7 | }, |
65 | Seerah-7 | [2] = { |
|
66 | 27 | Seerah-7 | text = SI_DIALOG_CANCEL, |
67 | 20 | Seerah-7 | }, |
68 | Seerah-7 | }, |
|
69 | Seerah-7 | } |
|
70 | 10 | Seerah-7 | |
71 | 11 | Seerah-7 | local scrollCount = 1 |
72 | 10 | Seerah-7 | function LAMCreateControl.panel(parent, panelData, controlName) |
73 | Seerah-7 | local control = wm:CreateTopLevelWindow(controlName) |
|
74 | Seerah-7 | control:SetParent(parent) |
|
75 | Seerah-7 | ||
76 | Seerah-7 | control.bg = wm:CreateControl(nil, control, CT_BACKDROP) |
|
77 | Seerah-7 | local bg = control.bg |
|
78 | 14 | Seerah-7 | bg:SetAnchorFill() |
79 | 10 | Seerah-7 | bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-Border.dds", 128, 16) |
80 | 25 | Seerah-7 | bg:SetCenterColor(0, 0, 0, 0) |
81 | 10 | Seerah-7 | |
82 | 12 | Seerah-7 | control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") |
83 | Seerah-7 | local label = control.label |
|
84 | Seerah-7 | label:SetAnchor(TOPLEFT, control, TOPLEFT, 10, 10) |
|
85 | 29 | Seerah-7 | label:SetText(panelData.displayName and panelData.displayName or panelData.name) |
86 | 12 | Seerah-7 | |
87 | 29 | Seerah-7 | if panelData.author or panelData.version then |
88 | Seerah-7 | control.info = wm:CreateControl(nil, control, CT_LABEL) |
|
89 | Seerah-7 | local info = control.info |
|
90 | Seerah-7 | --info:SetFont("ZoFontGameSmall") |
|
91 | Seerah-7 | info:SetFont("$(CHAT_FONT)|14|soft-shadow-thin") |
|
92 | Seerah-7 | info:SetColor(ZO_HIGHLIGHT_TEXT:UnpackRGBA()) |
|
93 | Seerah-7 | info:SetHeight(13) |
|
94 | Seerah-7 | info:SetAnchor(TOPRIGHT, control, BOTTOMRIGHT, -5, 2) |
|
95 | Seerah-7 | if panelData.author and panelData.version then |
|
96 | Seerah-7 | info:SetText("Version: "..panelData.version.." - Author: "..panelData.author) |
|
97 | Seerah-7 | elseif panelData.author then |
|
98 | Seerah-7 | info:SetText("Author: "..panelData.author) |
|
99 | Seerah-7 | else |
|
100 | Seerah-7 | info:SetText("Version: "..panelData.version) |
|
101 | Seerah-7 | end |
|
102 | Seerah-7 | end |
|
103 | Seerah-7 | ||
104 | 17 | Seerah-7 | control.container = wm:CreateControlFromVirtual("LAMAddonPanelContainer"..scrollCount, control, "ZO_ScrollContainer") |
105 | 11 | Seerah-7 | scrollCount = scrollCount + 1 |
106 | 17 | Seerah-7 | local container = control.container |
107 | Seerah-7 | container:SetAnchor(TOPLEFT, label, BOTTOMLEFT, 0, 20) |
|
108 | Seerah-7 | container:SetAnchor(BOTTOMRIGHT, control, BOTTOMRIGHT, -3, -3) |
|
109 | Seerah-7 | control.scroll = GetControl(control.container, "ScrollChild") |
|
110 | Seerah-7 | control.scroll:SetResizeToFitPadding(0, 20) |
|
111 | 11 | Seerah-7 | |
112 | 10 | Seerah-7 | if panelData.registerForDefaults then |
113 | 20 | Seerah-7 | control.defaultButton = wm:CreateControlFromVirtual(nil, control, "ZO_DefaultTextButton") |
114 | 10 | Seerah-7 | local defaultButton = control.defaultButton |
115 | 20 | Seerah-7 | defaultButton:SetFont("ZoFontDialogKeybindDescription") |
116 | Seerah-7 | defaultButton:SetHorizontalAlignment(TEXT_ALIGN_LEFT) |
|
117 | Seerah-7 | defaultButton:SetText("Reset To Defaults") |
|
118 | Seerah-7 | defaultButton:SetDimensions(200, 30) |
|
119 | 29 | Seerah-7 | defaultButton:SetAnchor(TOPLEFT, control, BOTTOMLEFT, 0, 2) |
120 | 20 | Seerah-7 | defaultButton:SetHandler("OnClicked", function() |
121 | 27 | Seerah-7 | ZO_Dialogs_ShowDialog("LAM_DEFAULTS", {control}) |
122 | 20 | Seerah-7 | end) |
123 | 10 | Seerah-7 | end |
124 | Seerah-7 | ||
125 | Seerah-7 | if panelData.registerForRefresh then |
|
126 | Seerah-7 | cm:RegisterCallback("LAM-RefreshPanel", RefreshPanel) |
|
127 | Seerah-7 | end |
|
128 | Seerah-7 | ||
129 | Seerah-7 | control.data = panelData |
|
130 | Seerah-7 | control.controlsToRefresh = {} |
|
131 | Seerah-7 | ||
132 | Seerah-7 | return control |
|
133 | Seerah-7 | end |