-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
config.lua
253 lines (208 loc) · 8.58 KB
/
config.lua
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
local _G = ShaguTweaks.GetGlobalEnv()
local T = ShaguTweaks.T
local GetExpansion = ShaguTweaks.GetExpansion
local mod = math.mod or mod
local current_config = {}
local max_width = 500
local max_height = 680
local settings = CreateFrame("Frame", "AdvancedSettingsGUI", UIParent)
settings:Hide()
table.insert(UISpecialFrames, "AdvancedSettingsGUI")
settings:SetScript("OnHide", function()
ShowUIPanel(GameMenuFrame)
UpdateMicroButtons()
end)
settings:SetPoint("CENTER", UIParent, "CENTER", 0, 32)
settings:SetWidth(max_width)
settings:SetMovable(true)
settings:EnableMouse(true)
settings:RegisterForDrag("LeftButton")
settings:SetScript("OnDragStart", function() this:StartMoving() end)
settings:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
settings:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 }
})
settings.scrollframe = CreateFrame('ScrollFrame', 'AdvancedSettingsGUIScrollframe', settings, 'UIPanelScrollFrameTemplate')
settings.scrollframe:SetWidth(max_width - 50)
settings.scrollframe:SetPoint('CENTER', settings, -16, 15)
settings.scrollframe:Hide()
settings.container = CreateFrame("Frame", "AdvancedSettingsGUIContainer", settings)
settings.title = CreateFrame("Frame", "AdvancedSettingsGUITtitle", settings)
settings.title:SetPoint("TOP", settings, "TOP", 0, 12)
settings.title:SetWidth(256)
settings.title:SetHeight(64)
settings.title.tex = settings.title:CreateTexture(nil, "MEDIUM")
settings.title.tex:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
settings.title.tex:SetAllPoints()
settings.title.text = settings.title:CreateFontString(nil, "HIGH", "GameFontNormal")
settings.title.text:SetText(T["Advanced Options"])
settings.title.text:SetPoint("TOP", 0, -14)
settings.cancel = CreateFrame("Button", "AdvancedSettingsGUICancel", settings, "GameMenuButtonTemplate")
settings.cancel:SetWidth(90)
settings.cancel:SetPoint("BOTTOMRIGHT", settings, "BOTTOMRIGHT", -17, 17)
settings.cancel:SetText(CANCEL)
settings.cancel:SetScript("OnClick", function()
current_config = {}
settings:Hide()
end)
settings.okay = CreateFrame("Button", "AdvancedSettingsGUIOkay", settings, "GameMenuButtonTemplate")
settings.okay:SetWidth(90)
settings.okay:SetPoint("RIGHT", settings.cancel, "LEFT", 0, 0)
settings.okay:SetText(OKAY)
settings.okay:SetScript("OnClick", function()
local reload
-- save temporary config to real config
for k, v in pairs(current_config) do
-- check if reload is required
if current_config[k] ~= ShaguTweaks_config[k] then
reload = true
end
-- set new config
ShaguTweaks_config[k] = v
end
-- reload the UI if required
if reload then
Minimap:SetMaskTexture("Textures\\MinimapMask")
ReloadUI()
end
settings:Hide()
end)
settings.defaults = CreateFrame("Button", "AdvancedSettingsGUICancel", settings, "GameMenuButtonTemplate")
settings.defaults:SetWidth(90)
settings.defaults:SetPoint("BOTTOMLEFT", settings, "BOTTOMLEFT", 17, 17)
settings.defaults:SetText(DEFAULTS)
settings.defaults:SetScript("OnClick", function()
settings:defaults()
end)
settings.load = function(self)
-- never use more than 3/4 of the screen size
max_height = math.min(UIParent:GetHeight()/UIParent:GetScale()*0.75, 680)
-- update window sizing according to screen
settings:SetHeight(max_height)
settings.scrollframe:SetHeight(max_height - 80)
settings.container:SetHeight(max_height - 30)
settings.entries = settings.entries or {}
local expansion = ShaguTweaks:GetExpansion()
-- sort all configs into categories
local gui = {}
for title, module in pairs(ShaguTweaks.mods) do
if module.expansions[expansion] then
local category = module.category or T["General"]
gui[category] = gui[category] or {}
gui[category][title] = module
end
end
local yoff = 25
local entrysize = 25
for category, entries in ShaguTweaks.spairs(gui) do
local entry, spacing = 1, 20
yoff = yoff + 12
-- add category background
settings.category = settings.category or {}
settings.category[category] = settings.category[category] or CreateFrame("Frame", nil, settings.container)
settings.category[category]:SetPoint("TOPLEFT", settings.container, "TOPLEFT", spacing, -yoff)
settings.category[category]:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 8, edgeSize = 16,
insets = { left = 3, right = 3, top = 3, bottom = 3 }
})
if ShaguTweaks.DarkMode then
settings.category[category]:SetBackdropColor(.1,.1,.1,1)
settings.category[category]:SetBackdropBorderColor(.2,.2,.2,1)
else
settings.category[category]:SetBackdropColor(.2,.2,.2,1)
settings.category[category]:SetBackdropBorderColor(.5,.5,.5,1)
end
-- add category title
settings.category[category].text = settings.category[category].text or settings.category[category]:CreateFontString(nil, "HIGH", "GameFontHighlightSmall")
settings.category[category].text:SetText(category)
settings.category[category].text:SetPoint("TOPLEFT", 5, 10)
yoff = yoff + spacing/2
for title, module in ShaguTweaks.spairs(entries) do
if not settings.entries[title] then
settings.entries[title] = CreateFrame("CheckButton", "AdvancedSettingsGUI" .. title, settings.category[category], "OptionsCheckButtonTemplate")
settings.entries[title]:SetHeight(24)
settings.entries[title]:SetWidth(24)
end
local button = _G["AdvancedSettingsGUI" .. title]
local text = _G["AdvancedSettingsGUI" .. title .. "Text"]
button.title = title
button:SetChecked(current_config[title] == 1 and true or nil)
button:SetPoint("TOPLEFT", settings.category[category], "TOPLEFT", mod(entry, 2) == 1 and 17 or 17+200, math.ceil(entry/2-1)*-entrysize-spacing/2)
-- add another yoff row
if mod(entry, 2) == 1 then yoff = yoff + entrysize end
local description = module.description
button:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_TOPLEFT");
GameTooltip:SetText(description, nil, nil, nil, nil, 1)
GameTooltip:Show()
end)
button:SetScript("OnHide", function()
GameTooltip:Hide()
end)
button:SetScript("OnClick", function()
if this:GetChecked() then
current_config[this.title] = 1
else
current_config[this.title] = 0
end
end)
text:SetText(title)
entry = entry + 1
end
yoff = yoff + spacing/2
settings.category[category]:SetPoint("BOTTOMRIGHT", settings.container, "TOPRIGHT", -spacing, -yoff)
end
-- set container size to required height
settings.container:SetHeight(yoff)
if yoff < max_height then
-- reduce base frame if possible
settings:SetHeight(yoff + 60)
settings.container:SetParent(settings)
settings.container:ClearAllPoints()
settings.container:SetPoint("CENTER", settings, 0, 20)
settings.container:SetWidth(max_width - 20)
settings.scrollframe:Hide()
elseif yoff > max_height then
-- set up scrollframe when needed
settings.container:SetParent(settings.scrollframe)
settings.container:SetHeight(settings.scrollframe:GetHeight())
settings.container:SetWidth(settings.scrollframe:GetWidth() + 20)
settings.scrollframe:SetScrollChild(settings.container)
settings.scrollframe:Show()
end
end
settings.defaults = function()
-- read default settings from modules
for title, mod in pairs(ShaguTweaks.mods) do
current_config[title] = mod.enabled and 1 or 0
end
settings:load()
end
settings:SetScript("OnShow", function()
-- read current config to temporary config
for k, v in pairs(ShaguTweaks_config) do
current_config[k] = v
end
settings:load()
end)
-- Add "Advanced Settings" Button to the Game Menu
GameMenuFrame:SetWidth(GameMenuFrame:GetWidth() - 30)
if GetExpansion() == 'tbc' then
GameMenuFrame:SetHeight(GameMenuFrame:GetHeight() + 10)
elseif GetExpansion() == 'vanilla' then
GameMenuFrame:SetHeight(GameMenuFrame:GetHeight() + 6)
end
local advanced = CreateFrame("Button", "GameMenuButtonAdvancedOptions", GameMenuFrame, "GameMenuButtonTemplate")
advanced:SetPoint("TOP", GameMenuButtonUIOptions, "BOTTOM", 0, -1)
advanced:SetText(T["Advanced Options"] .. "|cffffff00*")
advanced:SetScript("OnClick", function()
HideUIPanel(GameMenuFrame)
settings:Show()
end)
GameMenuButtonKeybindings:ClearAllPoints()
GameMenuButtonKeybindings:SetPoint("TOP", advanced, "BOTTOM", 0, -1)