forked from rockingdice/AutoCategory
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAddonMenu.lua
More file actions
executable file
·185 lines (142 loc) · 4.36 KB
/
AddonMenu.lua
File metadata and controls
executable file
·185 lines (142 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
-- aliases
local LAM = LibAddonMenu2
local SF = LibSFUtils
local auBagSet = AC_UI.BagSet
local auCatSet = AC_UI.CatSet
local auAppearanceMenu = AC_UI.AppearanceMenu
-- -------------------------------------------------------
-- function aliases
local divider = AC_UI.divider
-- -------------------------------------------------------
local warningDuplicatedName = AC_UI.warningDuplicatedName
local function UpdateDuplicateNameWarning()
local control = WINDOW_MANAGER:GetControlByName("AC_EDITBOX_EDITRULE_NAME", "")
if control then
control:UpdateWarning()
end
end
-- -------------------------------------------------------
-- Call refresh() on all BaseDD controls
function AC_UI.RefreshDropdownData()
auBagSet.refresh()
auCatSet.refresh()
end
-- updates the LAM cvt lists from our BaseDD objects
local RCPending = false
local function updtcb()
auBagSet.updateControls()
auCatSet.updateControls()
RCPending = false
end
local updtCB
function AC_UI.RefreshControls()
local waitTime = 500
if RCPending then return end
if not updtCB then
updtCB = SF.CallLater:NewSingle(updtcb, waitTime)
end
RCPending = true
updtCB:Start()
end
-- ------------------------------------------------------
local function RefreshPanel()
UpdateDuplicateNameWarning()
--restore warning
warningDuplicatedName.warningMessage = nil
end
-- increase the size of the editbox for a rule definition
local doneOnce = false
function AutoCategory.LengthenRuleBox()
local lines = 10
if doneOnce then return true end
-- change lines
local MIN_HEIGHT = 24
local control = WINDOW_MANAGER:GetControlByName("AC_EDITBOX_EDITRULE_RULE", "")
if control == nil or control.container == nil then return false end
doneOnce = true
local container = control.container
container:SetHeight(MIN_HEIGHT * lines)
control:SetHeight((MIN_HEIGHT * lines) + control.label:GetHeight())
return true
end
function AC_UI.ToggleSubmenu(typeString, open)
local control = WINDOW_MANAGER:GetControlByName(typeString, "")
if control then
control.open = open
if control.open then
control.animation:PlayFromStart()
else
control.animation:PlayFromEnd()
end
end
end
-- -------------------------------------------------------
local function CreatePanel()
return {
type = "panel",
name = AutoCategory.settingName,
displayName = AutoCategory.settingDisplayName,
author = AutoCategory.author,
version = AutoCategory.version,
slashCommand = "/ac",
registerForRefresh = true,
registerForDefaults = true,
resetFunc = function()
AutoCategory.ResetToDefaults()
AutoCategory.UpdateCurrentSavedVars() -- needed if swap acctwide on/off
AutoCategory.cacheInitialize()
auBagSet.clear()
auCatSet.clear()
AC_UI.RefreshDropdownData()
AC_UI.RefreshControls()
end,
}
end
function AutoCategory.AddonMenu_Init()
AutoCategory.cacheInitialize()
AC_UI.BagSet.Init()
AC_UI.DspWin_Init()
AC_UI.CatSet_Init()
AC_UI.AppearanceMenu_Init()
AC_UI.RefreshDropdownData()
AC_UI.RefreshControls()
local panelData = CreatePanel()
local optionsTable = {
-- Account Wide
{
type = "checkbox",
name = SI_AC_MENU_BS_CHECKBOX_ACCOUNT_WIDE_SETTING,
tooltip = SI_AC_MENU_BS_CHECKBOX_ACCOUNT_WIDE_SETTING_TOOLTIP,
getFunc = function()
return AutoCategory.charSaved.accountWide
end,
setFunc = function(value)
AutoCategory.charSaved.accountWide = value
AutoCategory.UpdateCurrentSavedVars() -- needed if swap acctwide on/off
auBagSet.clear()
auCatSet.clear()
AC_UI.RefreshDropdownData()
AC_UI.RefreshControls()
end,
},
divider(),
-- Bag Settings
auBagSet.controlDef(),
-- Category Settings
auCatSet.controlDef(),
-- General Settings
AC_UI.GeneralMenu,
-- Appearance Settings
auAppearanceMenu.controlDef(),
-- Gamepad settings
AC_UI.GamepadMenu,
}
if not LAM then return end
LAM:RegisterAddonPanel("AC_CATEGORY_SETTINGS", panelData)
LAM:RegisterOptionControls("AC_CATEGORY_SETTINGS", optionsTable)
CALLBACK_MANAGER:RegisterCallback("LAM-RefreshPanel", RefreshPanel)
CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", AutoCategory.LengthenRuleBox)
CALLBACK_MANAGER:RegisterCallback("LAM-PanelClosed", function()
AutoCategory.dspWin:SetHidden(true)
end)
end