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 | 11 | 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 | 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 | Seerah-7 | resetFunc = function() print("defaults reset") end, --(optional) custom function to run after settings are reset to defaults |
|
11 | Seerah-7 | } ]] |
|
12 | Seerah-7 | ||
13 | Seerah-7 | ||
14 | 14 | Seerah-7 | local widgetVersion = 8 |
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 | Seerah-7 | local panel = control.panel or control --callback can be fired by a single control or by the panel showing |
|
23 | 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 | 11 | Seerah-7 | if updateControl ~= control then |
28 | Seerah-7 | if updateControl.UpdateValue then |
|
29 | Seerah-7 | updateControl:UpdateValue() |
|
30 | Seerah-7 | end |
|
31 | Seerah-7 | if updateControl.UpdateDisabled then |
|
32 | Seerah-7 | updateControl:UpdateDisabled() |
|
33 | Seerah-7 | end |
|
34 | 10 | Seerah-7 | end |
35 | Seerah-7 | end |
|
36 | Seerah-7 | end |
|
37 | Seerah-7 | ||
38 | Seerah-7 | local function ForceDefaults(panel) |
|
39 | Seerah-7 | local panelControls = panel.controlsToRefresh |
|
40 | Seerah-7 | ||
41 | Seerah-7 | for i = 1, #panelControls do |
|
42 | Seerah-7 | local updateControl = panelControls[i] |
|
43 | Seerah-7 | if updateControl.UpdateValue and updateControl.data.default ~= nil then |
|
44 | Seerah-7 | updateControl:UpdateValue(true) |
|
45 | Seerah-7 | end |
|
46 | Seerah-7 | end |
|
47 | Seerah-7 | ||
48 | Seerah-7 | if panel.data.resetFunc then |
|
49 | Seerah-7 | panel.data.resetFunc() |
|
50 | Seerah-7 | end |
|
51 | 11 | Seerah-7 | |
52 | Seerah-7 | cm:FireCallbacks("LAM-RefreshPanel", panel) |
|
53 | 10 | Seerah-7 | end |
54 | Seerah-7 | ESO_Dialogs["LAM_DEFAULTS"] = { |
|
55 | Seerah-7 | title = { |
|
56 | 11 | Seerah-7 | text = SI_OPTIONS_RESET_TITLE, |
57 | 10 | Seerah-7 | }, |
58 | Seerah-7 | mainText = { |
|
59 | 11 | Seerah-7 | text = SI_OPTIONS_RESET_PROMPT, |
60 | 10 | Seerah-7 | align = TEXT_ALIGN_CENTER, |
61 | Seerah-7 | }, |
|
62 | Seerah-7 | buttons = { |
|
63 | Seerah-7 | [1] = { |
|
64 | Seerah-7 | text = SI_OPTIONS_RESET, |
|
65 | Seerah-7 | callback = function(dialog) ForceDefaults(dialog.data[1]) end, |
|
66 | Seerah-7 | }, |
|
67 | Seerah-7 | [2] = { |
|
68 | Seerah-7 | text = SI_DIALOG_CANCEL, |
|
69 | Seerah-7 | }, |
|
70 | Seerah-7 | }, |
|
71 | Seerah-7 | } |
|
72 | Seerah-7 | ||
73 | 14 | Seerah-7 | local callbackRegistered = false |
74 | Seerah-7 | LAMCreateControl.scrollCount = LAMCreateControl.scrollCount or 1 |
|
75 | 10 | Seerah-7 | function LAMCreateControl.panel(parent, panelData, controlName) |
76 | Seerah-7 | local control = wm:CreateTopLevelWindow(controlName) |
|
77 | Seerah-7 | control:SetParent(parent) |
|
78 | Seerah-7 | ||
79 | Seerah-7 | control.bg = wm:CreateControl(nil, control, CT_BACKDROP) |
|
80 | Seerah-7 | local bg = control.bg |
|
81 | Seerah-7 | bg:SetAnchorFill() |
|
82 | 13 | Seerah-7 | bg:SetEdgeTexture("EsoUI\\Art\\miscellaneous\\borderedinsettransparent_edgefile.dds", 128, 16) |
83 | 10 | Seerah-7 | bg:SetCenterColor(0, 0, 0, 0) |
84 | Seerah-7 | ||
85 | Seerah-7 | control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") |
|
86 | Seerah-7 | local label = control.label |
|
87 | Seerah-7 | label:SetAnchor(TOPLEFT, control, TOPLEFT, 10, 10) |
|
88 | 11 | Seerah-7 | label:SetText(panelData.displayName and panelData.displayName or panelData.name) |
89 | 10 | Seerah-7 | |
90 | 11 | Seerah-7 | if panelData.author or panelData.version then |
91 | Seerah-7 | control.info = wm:CreateControl(nil, control, CT_LABEL) |
|
92 | Seerah-7 | local info = control.info |
|
93 | Seerah-7 | info:SetFont("$(CHAT_FONT)|14|soft-shadow-thin") |
|
94 | Seerah-7 | info:SetColor(ZO_HIGHLIGHT_TEXT:UnpackRGBA()) |
|
95 | Seerah-7 | info:SetHeight(13) |
|
96 | Seerah-7 | info:SetAnchor(TOPRIGHT, control, BOTTOMRIGHT, -5, 2) |
|
97 | Seerah-7 | if panelData.author and panelData.version then |
|
98 | Seerah-7 | --info:SetText("Version: "..panelData.version.." - "..GetString(SI_ADDON_MANAGER_AUTHOR)..": "..panelData.author) |
|
99 | Seerah-7 | info:SetText(string.format("Version: %s - %s: %s", panelData.version, GetString(SI_ADDON_MANAGER_AUTHOR), panelData.author)) |
|
100 | Seerah-7 | elseif panelData.author then |
|
101 | Seerah-7 | info:SetText(string.format("%s: %s", GetString(SI_ADDON_MANAGER_AUTHOR), panelData.author)) |
|
102 | Seerah-7 | else |
|
103 | Seerah-7 | info:SetText("Version: "..panelData.version) |
|
104 | Seerah-7 | end |
|
105 | Seerah-7 | end |
|
106 | Seerah-7 | ||
107 | 14 | Seerah-7 | control.container = wm:CreateControlFromVirtual("LAMAddonPanelContainer"..LAMCreateControl.scrollCount, control, "ZO_ScrollContainer") |
108 | Seerah-7 | LAMCreateControl.scrollCount = LAMCreateControl.scrollCount + 1 |
|
109 | 10 | Seerah-7 | local container = control.container |
110 | Seerah-7 | container:SetAnchor(TOPLEFT, label, BOTTOMLEFT, 0, 20) |
|
111 | Seerah-7 | container:SetAnchor(BOTTOMRIGHT, control, BOTTOMRIGHT, -3, -3) |
|
112 | Seerah-7 | control.scroll = GetControl(control.container, "ScrollChild") |
|
113 | Seerah-7 | control.scroll:SetResizeToFitPadding(0, 20) |
|
114 | Seerah-7 | ||
115 | Seerah-7 | if panelData.registerForDefaults then |
|
116 | Seerah-7 | control.defaultButton = wm:CreateControlFromVirtual(nil, control, "ZO_DefaultTextButton") |
|
117 | Seerah-7 | local defaultButton = control.defaultButton |
|
118 | Seerah-7 | defaultButton:SetFont("ZoFontDialogKeybindDescription") |
|
119 | Seerah-7 | defaultButton:SetHorizontalAlignment(TEXT_ALIGN_LEFT) |
|
120 | 11 | Seerah-7 | --defaultButton:SetText("Reset To Defaults") |
121 | Seerah-7 | defaultButton:SetText(GetString(SI_OPTIONS_RESET_TITLE)) |
|
122 | 10 | Seerah-7 | defaultButton:SetDimensions(200, 30) |
123 | 11 | Seerah-7 | defaultButton:SetAnchor(TOPLEFT, control, BOTTOMLEFT, 0, 2) |
124 | 10 | Seerah-7 | defaultButton:SetHandler("OnClicked", function() |
125 | Seerah-7 | ZO_Dialogs_ShowDialog("LAM_DEFAULTS", {control}) |
|
126 | Seerah-7 | end) |
|
127 | Seerah-7 | end |
|
128 | Seerah-7 | ||
129 | 14 | Seerah-7 | if panelData.registerForRefresh and not callbackRegistered then --don't want to register our callback more than once |
130 | 10 | Seerah-7 | cm:RegisterCallback("LAM-RefreshPanel", RefreshPanel) |
131 | 14 | Seerah-7 | callbackRegistered = true |
132 | 10 | Seerah-7 | end |
133 | Seerah-7 | ||
134 | Seerah-7 | control.data = panelData |
|
135 | Seerah-7 | control.controlsToRefresh = {} |
|
136 | Seerah-7 | ||
137 | Seerah-7 | return control |
|
138 | Seerah-7 | end |