Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 36 | Seerah-7 | --[[submenuData = { |
2 | Seerah-7 | type = "submenu", |
|
3 | Seerah-7 | name = "Submenu Title", |
|
4 | Seerah-7 | tooltip = "My submenu tooltip", --(optional) |
|
5 | Seerah-7 | controls = {sliderData, buttonData} --(optional) used by LAM |
|
6 | Seerah-7 | reference = "MyAddonSubmenu" --(optional) unique global reference to control |
|
7 | Seerah-7 | } ]] |
|
8 | Seerah-7 | ||
9 | 53 | Seerah-7 | local widgetVersion = 7 |
10 | 36 | Seerah-7 | local LAM = LibStub("LibAddonMenu-2.0") |
11 | Seerah-7 | if not LAM:RegisterWidget("submenu", widgetVersion) then return end |
|
12 | Seerah-7 | ||
13 | Seerah-7 | local wm = WINDOW_MANAGER |
|
14 | Seerah-7 | local am = ANIMATION_MANAGER |
|
15 | 49 | Seerah-7 | local tinsert = table.insert |
16 | 36 | Seerah-7 | |
17 | Seerah-7 | ||
18 | 48 | Seerah-7 | local function UpdateValue(control) |
19 | Seerah-7 | control.label:SetText(control.data.name) |
|
20 | Seerah-7 | if control.data.tooltip then |
|
21 | 53 | Seerah-7 | --control.label.tooltipText = control.data.tooltip |
22 | Seerah-7 | control.label.data = {tooltipText = control.data.tooltip} |
|
23 | 48 | Seerah-7 | end |
24 | Seerah-7 | end |
|
25 | Seerah-7 | ||
26 | 45 | Seerah-7 | local function AnimateSubmenu(clicked) |
27 | Seerah-7 | local control = clicked:GetParent() |
|
28 | 36 | Seerah-7 | control.open = not control.open |
29 | Seerah-7 | ||
30 | Seerah-7 | if control.open then |
|
31 | Seerah-7 | control.animation:PlayFromStart() |
|
32 | Seerah-7 | else |
|
33 | Seerah-7 | control.animation:PlayFromEnd() |
|
34 | Seerah-7 | end |
|
35 | Seerah-7 | end |
|
36 | Seerah-7 | ||
37 | Seerah-7 | ||
38 | Seerah-7 | function LAMCreateControl.submenu(parent, submenuData, controlName) |
|
39 | Seerah-7 | local control = wm:CreateTopLevelWindow(controlName or submenuData.reference) |
|
40 | 45 | Seerah-7 | control:SetParent(parent.scroll or parent) |
41 | 36 | Seerah-7 | control.panel = parent |
42 | Seerah-7 | control:SetDimensions(523, 40) |
|
43 | Seerah-7 | ||
44 | Seerah-7 | control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") |
|
45 | Seerah-7 | local label = control.label |
|
46 | Seerah-7 | label:SetAnchor(TOPLEFT, control, TOPLEFT, 5, 5) |
|
47 | Seerah-7 | label:SetDimensions(520, 30) |
|
48 | Seerah-7 | label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) |
|
49 | Seerah-7 | label:SetText(submenuData.name) |
|
50 | Seerah-7 | label:SetMouseEnabled(true) |
|
51 | Seerah-7 | if submenuData.tooltip then |
|
52 | 53 | Seerah-7 | --label.tooltipText = submenuData.tooltip |
53 | Seerah-7 | label.data = {tooltipText = submenuData.tooltip} |
|
54 | 36 | Seerah-7 | label:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter) |
55 | Seerah-7 | label:SetHandler("OnMouseExit", ZO_Options_OnMouseExit) |
|
56 | Seerah-7 | end |
|
57 | Seerah-7 | ||
58 | Seerah-7 | control.scroll = wm:CreateControl(nil, control, CT_SCROLL) |
|
59 | Seerah-7 | local scroll = control.scroll |
|
60 | Seerah-7 | scroll:SetParent(control) |
|
61 | Seerah-7 | scroll:SetAnchor(TOPLEFT, label, BOTTOMLEFT, 0, 10) |
|
62 | 44 | Seerah-7 | scroll:SetDimensionConstraints(525, 0, 525, 2500) |
63 | 36 | Seerah-7 | |
64 | Seerah-7 | control.bg = wm:CreateControl(nil, label, CT_BACKDROP) |
|
65 | Seerah-7 | local bg = control.bg |
|
66 | Seerah-7 | bg:SetAnchor(TOPLEFT, label, TOPLEFT, -5, -5) |
|
67 | Seerah-7 | bg:SetAnchor(BOTTOMRIGHT, scroll, BOTTOMRIGHT, -7, 0) |
|
68 | Seerah-7 | bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-Border.dds", 128, 16) |
|
69 | Seerah-7 | bg:SetCenterTexture("EsoUI\\Art\\Tooltips\\UI-TooltipCenter.dds") |
|
70 | Seerah-7 | bg:SetInsets(16, 16, -16, -16) |
|
71 | Seerah-7 | ||
72 | Seerah-7 | control.arrow = wm:CreateControl(nil, bg, CT_TEXTURE) |
|
73 | Seerah-7 | local arrow = control.arrow |
|
74 | Seerah-7 | arrow:SetDimensions(28, 28) |
|
75 | Seerah-7 | arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortdown.dds") --list_sortup for the other way |
|
76 | Seerah-7 | arrow:SetAnchor(TOPRIGHT, bg, TOPRIGHT, -5, 5) |
|
77 | Seerah-7 | ||
78 | Seerah-7 | --figure out the cool animation later... |
|
79 | Seerah-7 | control.animation = am:CreateTimeline() |
|
80 | Seerah-7 | local animation = control.animation |
|
81 | Seerah-7 | animation:SetPlaybackType(ANIMATION_SIZE, 0) --2nd arg = loop count |
|
82 | Seerah-7 | --animation:SetDuration(1) |
|
83 | Seerah-7 | --animation:SetEasingFunction(ZO_LinearEase) --is this needed? |
|
84 | Seerah-7 | --animation:SetHeightStartAndEnd(40, 80) --SetStartAndEndHeight |
|
85 | Seerah-7 | --animation:SetStartAndEndHeight(40, 80) --SetStartAndEndHeight |
|
86 | Seerah-7 | --animation:SetAnimatedControl(control) |
|
87 | Seerah-7 | ||
88 | Seerah-7 | control:SetResizeToFitDescendents(true) |
|
89 | Seerah-7 | control.open = false |
|
90 | Seerah-7 | label:SetHandler("OnMouseUp", AnimateSubmenu) |
|
91 | Seerah-7 | animation:SetHandler("OnStop", function(self, completedPlaying) |
|
92 | Seerah-7 | scroll:SetResizeToFitDescendents(control.open) |
|
93 | Seerah-7 | if control.open then |
|
94 | Seerah-7 | control.arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortup.dds") |
|
95 | Seerah-7 | scroll:SetResizeToFitPadding(5, 20) |
|
96 | Seerah-7 | else |
|
97 | Seerah-7 | control.arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortdown.dds") |
|
98 | Seerah-7 | scroll:SetResizeToFitPadding(5, 0) |
|
99 | Seerah-7 | scroll:SetHeight(0) |
|
100 | Seerah-7 | end |
|
101 | Seerah-7 | end) |
|
102 | Seerah-7 | ||
103 | 45 | Seerah-7 | --small strip at the bottom of the submenu that you can click to close it |
104 | Seerah-7 | control.btmToggle = wm:CreateControl(nil, control, CT_TEXTURE) |
|
105 | Seerah-7 | local btmToggle = control.btmToggle |
|
106 | Seerah-7 | btmToggle:SetMouseEnabled(true) |
|
107 | Seerah-7 | btmToggle:SetAnchor(BOTTOMLEFT, control.scroll, BOTTOMLEFT) |
|
108 | Seerah-7 | btmToggle:SetAnchor(BOTTOMRIGHT, control.scroll, BOTTOMRIGHT) |
|
109 | Seerah-7 | btmToggle:SetHeight(15) |
|
110 | Seerah-7 | btmToggle:SetAlpha(0) |
|
111 | Seerah-7 | btmToggle:SetHandler("OnMouseUp", AnimateSubmenu) |
|
112 | Seerah-7 | ||
113 | 36 | Seerah-7 | control.data = submenuData |
114 | Seerah-7 | ||
115 | 48 | Seerah-7 | control.UpdateValue = UpdateValue |
116 | Seerah-7 | ||
117 | Seerah-7 | if control.panel.data.registerForRefresh or control.panel.data.registerForDefaults then --if our parent window wants to refresh controls, then add this to the list |
|
118 | Seerah-7 | tinsert(control.panel.controlsToRefresh, control) |
|
119 | Seerah-7 | end |
|
120 | Seerah-7 | ||
121 | 36 | Seerah-7 | return control |
122 | Seerah-7 | end |
|
123 | Seerah-7 |