-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDifficultBulletinBoardOptionFrame.lua
426 lines (333 loc) · 18.8 KB
/
DifficultBulletinBoardOptionFrame.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
DifficultBulletinBoard = DifficultBulletinBoard or {}
DifficultBulletinBoardVars = DifficultBulletinBoardVars or {}
DifficultBulletinBoardDefaults = DifficultBulletinBoardDefaults or {}
DifficultBulletinBoardSavedVariables = DifficultBulletinBoardSavedVariables or {}
local optionFrame = DifficultBulletinBoardOptionFrame
local optionYOffset = 30 -- Starting vertical offset for the first option
local optionScrollChild
local tagsTextBoxWidthDelta = 260
local tempGroupTags = {}
local tempProfessionTags = {}
local tempHardcoreTags = {}
-- Option Data for Base Font Size
local baseFontSizeOptionObject = {
frameName = "DifficultBulletinBoardOptionFrame_Font_Size_Input",
labelText = "Base Font Size:",
labelToolTip = "Adjusts the base font size for text. Other font sizes (e.g., titles) are calculated relative to this value. For example, if the base font size is 14, titles may be set 2 points higher.",
}
-- Option Data for Placeholders per Group Topic
local groupPlaceholdersOptionObject = {
frameName = "DifficultBulletinBoardOptionFrame_Group_Placeholder_Input",
labelText = "Entries per Group Topic:",
labelToolTip = "Defines the number of entries displayed for each group topic entry.",
}
-- Option Data for Placeholders per Profession Topic
local professionPlaceholdersOptionObject = {
frameName = "DifficultBulletinBoardOptionFrame_Profession_Placeholder_Input",
labelText = "Entries per Profession Topic:",
labelToolTip = "Specifies the number of entries displayed for each profession topic entry.",
}
-- Option Data for Placeholders per Hardcore Topic
local hardcorePlaceholdersOptionObject = {
frameName = "DifficultBulletinBoardOptionFrame_Hardcore_Placeholder_Input",
labelText = "Entries per Hardcore Topic:",
labelToolTip = "Sets the number of entries displayed for each hardcore topic entry.",
}
local groupTopicListObject = {
frameName = "DifficultBulletinBoardOptionFrame_Group_TopicList",
labelText = "Select the Group Topics to Observe:",
labelToolTip = "Check to enable scanning for messages related to this group topic in chat. Uncheck to stop searching.\n\nTags should be separated by spaces, and only the first match will be searched. Once a match is found, the message will be added to the bulletin board.",
}
local professionTopicListObject = {
frameName = "DifficultBulletinBoardOptionFrame_Profession_TopicList",
labelText = "Select the Profession Topics to Observe:",
labelToolTip = "Check to enable scanning for messages related to this profession topic in chat. Uncheck to stop searching.\n\nTags should be separated by spaces, and only the first match will be searched. Once a match is found, the message will be added to the bulletin board.",
}
local hardcoreTopicListObject = {
frameName = "DifficultBulletinBoardOptionFrame_Hardcore_TopicList",
labelText = "Select the Hardcore Topics to Observe:",
labelToolTip = "Check to enable scanning for messages related to this hardcore topic in chat. Uncheck to stop searching.\n\nTags should be separated by spaces, and only the first match will be searched. Once a match is found, the message will be added to the bulletin board.",
}
-- Option Data for the timestamp format
local timeFormatDropDownOptionObject = {
frameName = "DifficultBulletinBoardOptionFrame_Time_Dropdown",
labelText = "Select Time Format:",
labelToolTip = "Choose a time format for displaying timestamps.\n\nFixed format displays the exact time, while elapsed format shows the time since the message was posted.",
items = {
{ text = "Fixed Time (HH:MM:SS)", value = "fixed"},
{ text = "Elapsed Time (MM:SS)", value = "elapsed"}
}
}
-- Option Data for MainFrame sound being played
local mainFrameSoundDropDownOptionObject = {
frameName = "DifficultBulletinBoardOptionFrame_MainFrame_Sound_Dropdown",
labelText = "Play Sound for Bulletin Board:",
labelToolTip = "Enable or disable the sound that plays when the Bulletin Board is opened and closed.",
items = {
{ text = "Enable Sound", value = "true" },
{ text = "Disable Sound", value = "false" }
}
}
-- Option Data for OptionFrame sound being played
local optionFrameSoundDropDownOptionObject = {
frameName = "DifficultBulletinBoardOptionFrame_OptionFrame_Sound_Dropdown",
labelText = "Play Sound for Option Window:",
labelToolTip = "Enable or disable the sound that plays when the Optin Window is opened and closed.",
items = {
{ text = "Enable Sound", value = "true" },
{ text = "Disable Sound", value = "false" }
}
}
-- Option Data for the timestamp format
local serverTimePositionDropDownOptionObject = {
frameName = "DifficultBulletinBoardOptionFrame_Server_Time_Dropdown",
labelText = "Select Server Time Position:",
labelToolTip = "Choose where to display the server time or disable it:\n\n" ..
"Disabled: Hides the server time completely.\n\n" ..
"Top Left: Displays the server time to the left of the title, at the top of the bulletin board.\n\n" ..
"To the Right of Tab Buttons: Displays the server time on the same level as the tab buttons, sticking to the right above where the time columns normally are.",
items = {
{ text = "Top Left of Title", value = "top-left" },
{ text = "To the Right of Tab Buttons", value = "right-of-tabs" },
{ text = "Disable Time Display", value = "disabled" }
}
}
local fontSizeOptionInputBox
local serverTimePositionDropDown
local timeFormatDropDown
local mainFrameSoundDropDown
local optionFrameSoundDropDown
local groupOptionInputBox
local professionOptionInputBox
local hardcoreOptionInputBox
local function print(string)
--DEFAULT_CHAT_FRAME:AddMessage(string)
end
local function overwriteTagsForAllTopics(allTopics, tempTags)
for _, topic in ipairs(allTopics) do
if tempTags[topic.name] then
local newTags = tempTags[topic.name]
topic.tags = newTags
print("Tags for topic '" .. topic.name .. "' have been updated:")
for _, tag in ipairs(newTags) do print("- " .. tag) end
else
print("No tags found for topic '" .. topic.name .. "' in tempTags.")
end
end
end
local function addScrollFrameToOptionFrame()
local parentFrame = optionFrame
-- Create the ScrollFrame
local optionScrollFrame = CreateFrame("ScrollFrame", "DifficultBulletinBoardOptionFrame_ScrollFrame", parentFrame, "UIPanelScrollFrameTemplate")
optionScrollFrame:EnableMouseWheel(true)
-- Set ScrollFrame anchors
optionScrollFrame:SetPoint("TOPLEFT", parentFrame, "TOPLEFT", 0, -50)
optionScrollFrame:SetPoint("BOTTOMRIGHT", parentFrame, "BOTTOMRIGHT", -27, 75)
optionScrollFrame:SetWidth(460)
optionScrollFrame:SetHeight(1)
-- Create the ScrollChild
optionScrollChild = CreateFrame("Frame", nil, optionScrollFrame)
optionScrollChild:SetWidth(480)
optionScrollChild:SetHeight(1)
optionScrollFrame:SetScrollChild(optionScrollChild)
end
local function addDropDownOptionToOptionFrame(options, defaultValue)
-- Adjust vertical offset for the dropdown
optionYOffset = optionYOffset - 50
-- Create a frame to hold the label and enable mouse interactions
local labelFrame = CreateFrame("Frame", nil, optionScrollChild)
labelFrame:SetPoint("TOPLEFT", optionScrollChild, "TOPLEFT", 0, optionYOffset)
labelFrame:SetHeight(20)
-- Create the label (FontString) inside the frame
local label = labelFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
label:SetAllPoints(labelFrame)
label:SetText(options.labelText)
label:SetFont("Fonts\\FRIZQT__.TTF", DifficultBulletinBoardVars.fontSize)
-- Set labelFrame width based on the text width with padding
labelFrame:SetWidth(label:GetStringWidth() + 20)
-- Add a GameTooltip to the labelFrame
labelFrame:EnableMouse(true)
labelFrame:SetScript("OnEnter", function()
GameTooltip:SetOwner(labelFrame, "ANCHOR_RIGHT")
GameTooltip:SetText(options.labelToolTip, nil, nil, nil, nil, true)
GameTooltip:Show()
end)
labelFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
-- Create the dropdown menu
local dropdown = CreateFrame("Frame", options.frameName, optionScrollChild, "UIDropDownMenuTemplate")
dropdown:SetPoint("LEFT", labelFrame, "RIGHT", 0, 0)
local maxWidth = 0
-- Initialize the dropdown menu
UIDropDownMenu_Initialize(dropdown, function()
for id, item in ipairs(options.items) do
local info = {}
info.text = item.text
info.value = item.value
-- Create a hidden FontString so we can get the width of the string (this sucks I know...)
local fontString = dropdown:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
fontString:SetText(info.text)
fontString:Hide()
local textWidth = fontString:GetStringWidth()
if textWidth > maxWidth then
maxWidth = textWidth
end
info.func = function()
UIDropDownMenu_SetSelectedValue(dropdown, info.value, false)
print("Selected: " .. info.value .. " " .. info.text)
print(UIDropDownMenu_GetText(dropdown))
print(UIDropDownMenu_GetSelectedValue(dropdown))
end
UIDropDownMenu_AddButton(info)
end
end)
UIDropDownMenu_SetWidth(maxWidth + 20, dropdown)
-- Set the default value
UIDropDownMenu_SetSelectedValue(dropdown, defaultValue, false)
return dropdown
end
local function addInputBoxOptionToOptionFrame(option, value)
-- Adjust Y offset for the new option
optionYOffset = optionYOffset - 50
-- Create a frame to hold the label and allow for mouse interactions
local labelFrame = CreateFrame("Frame", nil, optionScrollChild)
labelFrame:SetPoint("TOPLEFT", optionScrollChild, "TOPLEFT", 0, optionYOffset)
labelFrame:SetHeight(20)
-- Create the label (FontString) inside the frame
local label = labelFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
label:SetAllPoints(labelFrame) -- Make the label take up the full frame
label:SetText(option.labelText)
label:SetFont("Fonts\\FRIZQT__.TTF", DifficultBulletinBoardVars.fontSize)
--set labelFrame width afterwards with padding so the label is not cut off
labelFrame:SetWidth(label:GetStringWidth() + 20)
-- Add a GameTooltip to the labelFrame
labelFrame:EnableMouse(true) -- Enable mouse interactions for the frame
labelFrame:SetScript("OnEnter", function()
GameTooltip:SetOwner(labelFrame, "ANCHOR_RIGHT")
GameTooltip:SetText(option.labelToolTip, nil, nil, nil, nil, true)
GameTooltip:Show()
end)
labelFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
-- Create the input field (EditBox)
local inputBox = CreateFrame("EditBox", option.frameName, optionScrollChild, "InputBoxTemplate")
inputBox:SetPoint("LEFT", labelFrame, "RIGHT", 10, 0)
inputBox:SetWidth(30)
inputBox:SetHeight(20)
inputBox:SetText(value)
inputBox:EnableMouse(true)
inputBox:SetAutoFocus(false)
return inputBox
end
local tempTagsTextBoxes = {}
local function addTopicListToOptionFrame(topicObject, topicList)
local parentFrame = optionScrollChild
local tempTags = {}
optionYOffset = optionYOffset - 30
-- Create a frame to hold the label and allow for mouse interactions
local labelFrame = CreateFrame("Frame", nil, optionScrollChild)
labelFrame:SetPoint("TOPLEFT", optionScrollChild, "TOPLEFT", 0, optionYOffset)
labelFrame:SetHeight(20)
-- Create the label (FontString) inside the frame
local scrollLabel = labelFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
scrollLabel:SetAllPoints(labelFrame) -- Make the label take up the full frame
scrollLabel:SetText(topicObject.labelText)
scrollLabel:SetFont("Fonts\\FRIZQT__.TTF", DifficultBulletinBoardVars.fontSize)
--set labelFrame width afterwards with padding so the label is not cut off
labelFrame:SetWidth(scrollLabel:GetStringWidth() + 20)
-- Add a GameTooltip to the labelFrame
labelFrame:EnableMouse(true) -- Enable mouse interactions for the frame
labelFrame:SetScript("OnEnter", function()
GameTooltip:SetOwner(labelFrame, "ANCHOR_RIGHT")
GameTooltip:SetText(topicObject.labelToolTip, nil, nil, nil, nil, true)
GameTooltip:Show()
end)
labelFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
for _, topic in ipairs(topicList) do
optionYOffset = optionYOffset - 30 -- Adjust the vertical offset for the next row
local checkbox = CreateFrame("CheckButton", "$parent_" .. topic.name .. "_Checkbox", parentFrame, "UICheckButtonTemplate")
checkbox:SetPoint("TOPLEFT", parentFrame, "TOPLEFT", 10, optionYOffset)
checkbox:SetWidth(25)
checkbox:SetHeight(25)
checkbox:SetChecked(topic.selected)
local currentTopic = topic
checkbox:SetScript("OnClick", function()
currentTopic.selected = checkbox:GetChecked()
end)
-- Add a label next to the checkbox displaying the topic
local topicLabel = parentFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
topicLabel:SetPoint("LEFT", checkbox, "RIGHT", 10, 0)
topicLabel:SetText(topic.name)
topicLabel:SetFont("Fonts\\FRIZQT__.TTF", DifficultBulletinBoardVars.fontSize - 2)
topicLabel:SetJustifyH("LEFT")
topicLabel:SetWidth(175)
-- Add a text box next to the topic label for tags input
local tagsTextBox = CreateFrame("EditBox", "$parent_" .. topic.name .. "_TagsTextBox", parentFrame, "InputBoxTemplate")
tagsTextBox:SetPoint("LEFT", topicLabel, "RIGHT", 10, 0)
tagsTextBox:SetWidth(200)
tagsTextBox:SetHeight(20)
tagsTextBox:SetText(table.concat(topic.tags, " "))
tagsTextBox:EnableMouse(true)
tagsTextBox:SetAutoFocus(false)
local topicName = topic.name -- save a reference for the onTextChanged event
tagsTextBox:SetScript("OnTextChanged", function()
local enteredText = this:GetText()
tempTags[topicName] = DifficultBulletinBoard.SplitIntoLowerWords(enteredText)
end)
table.insert(tempTagsTextBoxes, tagsTextBox)
end
return tempTags
end
function DifficultBulletinBoardOptionFrame.InitializeOptionFrame()
addScrollFrameToOptionFrame()
fontSizeOptionInputBox = addInputBoxOptionToOptionFrame(baseFontSizeOptionObject, DifficultBulletinBoardVars.fontSize)
serverTimePositionDropDown = addDropDownOptionToOptionFrame(serverTimePositionDropDownOptionObject, DifficultBulletinBoardVars.serverTimePosition)
timeFormatDropDown = addDropDownOptionToOptionFrame(timeFormatDropDownOptionObject, DifficultBulletinBoardVars.timeFormat)
mainFrameSoundDropDown = addDropDownOptionToOptionFrame(mainFrameSoundDropDownOptionObject, DifficultBulletinBoardVars.mainFrameSound)
optionFrameSoundDropDown = addDropDownOptionToOptionFrame(optionFrameSoundDropDownOptionObject, DifficultBulletinBoardVars.optionFrameSound)
groupOptionInputBox = addInputBoxOptionToOptionFrame(groupPlaceholdersOptionObject, DifficultBulletinBoardVars.numberOfGroupPlaceholders)
tempGroupTags = addTopicListToOptionFrame(groupTopicListObject, DifficultBulletinBoardVars.allGroupTopics)
professionOptionInputBox = addInputBoxOptionToOptionFrame(professionPlaceholdersOptionObject, DifficultBulletinBoardVars.numberOfProfessionPlaceholders)
tempProfessionTags= addTopicListToOptionFrame(professionTopicListObject, DifficultBulletinBoardVars.allProfessionTopics)
hardcoreOptionInputBox = addInputBoxOptionToOptionFrame(hardcorePlaceholdersOptionObject,DifficultBulletinBoardVars.numberOfHardcorePlaceholders)
tempHardcoreTags = addTopicListToOptionFrame(hardcoreTopicListObject, DifficultBulletinBoardVars.allHardcoreTopics)
end
function DifficultBulletinBoard_ResetVariablesAndReload()
DifficultBulletinBoardSavedVariables.version = DifficultBulletinBoardDefaults.version
DifficultBulletinBoardSavedVariables.fontSize = DifficultBulletinBoardDefaults.defaultFontSize
DifficultBulletinBoardSavedVariables.serverTimePosition = DifficultBulletinBoardDefaults.defaultServerTimePosition
DifficultBulletinBoardSavedVariables.timeFormat = DifficultBulletinBoardDefaults.defaultTimeFormat
DifficultBulletinBoardSavedVariables.mainFrameSound = DifficultBulletinBoardDefaults.defaultMainFrameSound
DifficultBulletinBoardSavedVariables.optionFrameSound = DifficultBulletinBoardDefaults.defaultOptionFrameSound
DifficultBulletinBoardSavedVariables.numberOfGroupPlaceholders = DifficultBulletinBoardDefaults.defaultNumberOfGroupPlaceholders
DifficultBulletinBoardSavedVariables.numberOfProfessionPlaceholders = DifficultBulletinBoardDefaults.defaultNumberOfProfessionPlaceholders
DifficultBulletinBoardSavedVariables.numberOfHardcorePlaceholders = DifficultBulletinBoardDefaults.defaultNumberOfHardcorePlaceholders
DifficultBulletinBoardSavedVariables.activeGroupTopics = DifficultBulletinBoardDefaults.defaultGroupTopics
DifficultBulletinBoardSavedVariables.activeProfessionTopics = DifficultBulletinBoardDefaults.defaultProfessionTopics
DifficultBulletinBoardSavedVariables.activeHardcoreTopics = DifficultBulletinBoardDefaults.defaultHardcoreTopics
ReloadUI();
end
function DifficultBulletinBoard_SaveVariablesAndReload()
DifficultBulletinBoardSavedVariables.fontSize = fontSizeOptionInputBox:GetText()
DifficultBulletinBoardSavedVariables.timeFormat = UIDropDownMenu_GetSelectedValue(timeFormatDropDown)
DifficultBulletinBoardSavedVariables.serverTimePosition = UIDropDownMenu_GetSelectedValue(serverTimePositionDropDown)
DifficultBulletinBoardSavedVariables.mainFrameSound = UIDropDownMenu_GetSelectedValue(mainFrameSoundDropDown)
DifficultBulletinBoardSavedVariables.optionFrameSound = UIDropDownMenu_GetSelectedValue(optionFrameSoundDropDown)
DifficultBulletinBoardSavedVariables.numberOfGroupPlaceholders = groupOptionInputBox:GetText()
DifficultBulletinBoardSavedVariables.numberOfProfessionPlaceholders = professionOptionInputBox:GetText()
DifficultBulletinBoardSavedVariables.numberOfHardcorePlaceholders = hardcoreOptionInputBox:GetText()
overwriteTagsForAllTopics(DifficultBulletinBoardVars.allGroupTopics, tempGroupTags);
overwriteTagsForAllTopics(DifficultBulletinBoardVars.allProfessionTopics, tempProfessionTags);
overwriteTagsForAllTopics(DifficultBulletinBoardVars.allHardcoreTopics, tempHardcoreTags);
ReloadUI();
end
optionFrame:SetScript("OnSizeChanged", function()
local tagsTextBoxWidth = optionFrame:GetWidth() - tagsTextBoxWidthDelta
for _, msgFrame in ipairs(tempTagsTextBoxes) do
msgFrame:SetWidth(tagsTextBoxWidth)
end
end)