-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataDisplay.lua
More file actions
526 lines (425 loc) · 21.4 KB
/
Copy pathDataDisplay.lua
File metadata and controls
526 lines (425 loc) · 21.4 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
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
function ClearDynamicContent(contentArea)
if contentArea.dynamicContentList then
for _, content in ipairs(contentArea.dynamicContentList) do
content:Hide()
content:SetParent(nil)
end
-- Clear the list after cleaning up
contentArea.dynamicContentList = {}
end
end
function ShowHideFrame(tabIndex)
local frame = _G["YippYappDataDisplayFrame"]
if not frame then -- Ensure the frame is created if it doesn't exist
frame = CreateDisplayFrame()
UpdateBlacklistContent(YippYappGuildTools_BlacklistDB)
UpdateProfessionsContent(YippYappGuildTools_ProfessionsDB)
frame:Show()
Tab_OnClick(frame.tabs[tabIndex], frame)
elseif frame:IsShown() and frame.selectedTab == tabIndex then
frame:Hide()
else
UpdateBlacklistContent(YippYappGuildTools_BlacklistDB)
UpdateProfessionsContent(YippYappGuildTools_ProfessionsDB)
frame:Show()
-- Update 'frame.selectedTab' to reflect the newly selected tab
frame.selectedTab = tabIndex
PanelTemplates_SetTab(frame, tabIndex)
Tab_OnClick(frame.tabs[tabIndex], frame)
end
end
function CreateTabs(frame)
frame.tabs = {}
local titles = {localeTable.professions, localeTable.blacklisted}
for i, title in ipairs(titles) do
local tab = CreateFrame("Button", "$parentTab"..i, frame, "CharacterFrameTabButtonTemplate")
tab:SetID(i)
tab:SetText(title)
tab:GetFontString():SetWidth(0)
tab:SetScript("OnClick", function() Tab_OnClick(tab, frame) end)
-- Adjust tab width based on the text width
local textWidth = tab:GetFontString():GetWidth()
local padding = 20 -- Adjust padding as needed
local tabWidth = textWidth + padding
tab:SetWidth(tabWidth)
PanelTemplates_TabResize(tab, padding, 100)
if i == 1 then
tab:SetPoint("TOPLEFT", frame, "BOTTOMLEFT", 5, 4)
else
tab:SetPoint("LEFT", frame.tabs[i-1], "RIGHT", -16, 0)
end
frame.tabs[i] = tab
end
PanelTemplates_SetNumTabs(frame, #titles)
PanelTemplates_UpdateTabs(frame)
-- Automatically select and display the first tab's content upon creation
PanelTemplates_SetTab(frame, 1)
Tab_OnClick(frame.tabs[1], frame)
end
local function Capitalize(str)
return str:sub(1,1):upper() .. str:sub(2):lower()
end
local function GetTimeDifference(lastUpdated)
local currentTime = GetServerTime()
local difference = currentTime - lastUpdated
local minutes = math.floor(difference / 60)
local hours = math.floor(minutes / 60)
local days = math.floor(hours / 24)
if days > 0 then
return days .. (days == 1 and " day" or " days") .. " ago"
elseif hours > 0 then
return hours .. (hours == 1 and " hour" or " hours") .. " ago"
else
return minutes .. (minutes == 1 and " minute" or " minutes") .. " ago"
end
end
local function ValidateInputs(name, class, reason)
-- Define a list of valid classes
local validClasses = {
["Warrior"] = true,
["Paladin"] = true,
["Hunter"] = true,
["Rogue"] = true,
["Priest"] = true,
["Shaman"] = true,
["Mage"] = true,
["Warlock"] = true,
["Druid"] = true,
}
class = Capitalize(class:lower())
if name == "" or class == "" or reason == "" then
return false, "All fields must be filled out."
end
if not validClasses[class] then
return false, "Invalid class."
end
return true, ""
end
function CreateBlacklistInput(labelText, parent, labelPoint, inputPoint, relativeTo, offsetX, offsetY, labelWidth, inputWidth)
local label = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint(labelPoint, relativeTo, offsetX, offsetY)
label:SetText(labelText)
label:SetWidth(labelWidth)
local input = CreateFrame("EditBox", nil, parent, "InputBoxTemplate")
-- Adjust input position to be aligned with the frame, but shifted right to accommodate label
input:SetPoint(inputPoint, label, "TOPRIGHT", -15, 5) -- Offset adjusted for visual alignment
input:SetSize(inputWidth, 20)
input:SetAutoFocus(false) -- Avoid automatic focus
input:SetFontObject("ChatFontNormal")
input:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
input:SetFrameLevel(parent:GetFrameLevel() + 1) -- Ensure input is above the label in the frame stack
return input
end
function CreateBlacklistInputFields(inputArea)
local labelWidth = 100
local inputWidth = 150
local nameInput = CreateBlacklistInput(localeTable.inputName, inputArea, "TOPLEFT", "TOPLEFT", inputArea, -15, -13, labelWidth, inputWidth)
local classInput = CreateBlacklistInput(localeTable.inputClass, inputArea, "TOPLEFT", "TOPLEFT", inputArea, -15, -35, labelWidth, inputWidth)
local reasonInput = CreateBlacklistInput(localeTable.inputReason, inputArea, "TOPLEFT", "TOPLEFT", inputArea, -15, -57, labelWidth, inputWidth)
--Submit button
local submitButton = CreateFrame("Button", nil, inputArea, "GameMenuButtonTemplate")
submitButton:SetPoint("TOPLEFT", inputArea, "BOTTOMLEFT", 5, 35)
submitButton:SetSize(120, 25)
submitButton:SetText(localeTable.submitButton)
submitButton:SetScript("OnClick", function()
-- Grab inputs
local name = nameInput:GetText()
local class = classInput:GetText()
local reason = reasonInput:GetText()
-- Validate inputs
local isValid, errorMessage = ValidateInputs(name, class, reason)
if isValid then
-- Add to blacklist (ensure your AddToBlacklist function handles this correctly)
local characterData = {
name = Capitalize(name),
class = Capitalize(class),
reason = reason
}
AddToBlacklist(characterData)
-- Clear inputs after successful submission
nameInput:SetText("")
classInput:SetText("")
reasonInput:SetText("")
UpdateBlacklistContent(YippYappGuildTools_BlacklistDB)
SendBlacklistDataToGuild()
ShowHideFrame(2)
else
UpdateStatusReport(errorMessage)
end
end)
-- Remove Button
local removeButton = CreateFrame("Button", nil, inputArea, "GameMenuButtonTemplate")
removeButton:SetPoint("LEFT", submitButton, "RIGHT", 5, 0)
removeButton:SetSize(120, 25)
removeButton:SetText(localeTable.removeButton)
removeButton:SetScript("OnClick", function()
local name = nameInput:GetText()
name = Capitalize(name)
if name ~= "" then
if YippYappGuildTools_BlacklistDB[name] then
RemoveFromBlacklist(name)
UpdateStatusReport(name.." removed from blacklist")
-- Update the blacklist tab content with the new data
UpdateBlacklistContent(YippYappGuildTools_BlacklistDB)
ShowHideFrame(2)
else
-- Display error message if name input is not in db
UpdateStatusReport("Character does not exist in DB.")
end
else
-- Display error message if name input is empty
UpdateStatusReport("Please enter a name to remove.")
end
end)
-- Status Report Area
local statusReport = inputArea:CreateFontString(nil, "OVERLAY", "GameFontNormal")
statusReport:SetPoint("TOPLEFT", nameInput, "TOPRIGHT", 10, 0)
statusReport:SetWidth(inputArea:GetWidth())
statusReport:SetJustifyH("LEFT")
function UpdateStatusReport(message)
statusReport:SetText(message)
end
end
function CreateInputArea(frame, inputAreaHeight, bottomAreaHeight)
local inputArea = CreateFrame("Frame", nil, frame, "BackdropTemplate")
inputArea:SetHeight(inputAreaHeight) -- Adjust height as needed
inputArea:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 8, 25)
inputArea:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -8, bottomAreaHeight)
inputArea:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 16,
insets = { left = 5, right = 5, top = 5, bottom = 5 }
})
inputArea:SetFrameLevel(frame:GetFrameLevel() + 1)
frame.inputArea = inputArea
CreateBlacklistInputFields(inputArea)
end
function CreateContentAreas(frame)
-- Professions Content
local professionsContent = CreateFrame("Frame", "$parentProfessionsContent", frame.content)
professionsContent:SetSize(frame.content:GetWidth(), frame.content:GetHeight())
professionsContent:SetPoint("TOPLEFT")
professionsContent:Hide() -- Start hidden
-- Blacklist Content
local blacklistContent = CreateFrame("Frame", "$parentBlacklistContent", frame.content)
blacklistContent:SetSize(frame.content:GetWidth(), frame.content:GetHeight())
blacklistContent:SetPoint("TOPLEFT")
blacklistContent:Hide() -- Start hidden
-- Add title for Blacklist Content
-- local blacklistTitle = blacklistContent:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
-- blacklistTitle:SetPoint("TOPLEFT", blacklistContent, "TOPLEFT", 10, 0)
-- blacklistTitle:SetText("FOOKIN BLACKLISTED")
frame.professionsContent = professionsContent
frame.blacklistContent = blacklistContent
end
function Tab_OnClick(tab, frame)
local tabIndex = tab:GetID()
PanelTemplates_SetTab(frame, tabIndex)
frame.selectedTab = tabIndex
frame.professionsScrollFrame:Hide()
frame.blacklistScrollFrame:Hide()
-- Assume inputArea is properly initialized and part of the 'frame'
if frame.inputArea then
if tabIndex == 1 then
frame.professionsScrollFrame:Show()
frame.inputArea:Hide()
elseif tabIndex == 2 then
frame.blacklistScrollFrame:Show()
frame.inputArea:Show()
end
end
end
function CreateBottomFrame(frame, bottomAreaHeight)
-- Credit Bar similar to the Title Bar at the bottom
local bottomBar = CreateFrame("Frame", nil, frame, "BackdropTemplate")
bottomBar:SetHeight(bottomAreaHeight) -- Similar to the title bar
bottomBar:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 8, 5)
bottomBar:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -8, 5)
bottomBar:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", -- Background texture
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", -- Border texture
tile = true, tileSize = 32, edgeSize = 16,
insets = { left = 5, right = 5, top = 5, bottom = 5 }
})
local creditText = bottomBar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
creditText:SetPoint("CENTER", bottomBar, "CENTER", 0, 0)
creditText:SetText("Created by Ryggsekken-ChaosBolt")
end
function CreateDisplayFrame()
-- Constants for the proportion of the main frame dedicated to each area
local PROFESSION_AREA_PROPORTION = 0.966 -- 96,6 % of the frame height for professions
local BLACKLIST_AREA_PROPORTION = 0.736 -- 73,6% of the frame height for professions
local INPUT_AREA_PROPORTION = 0.22 -- 22% of the frame height for inputs
local BOTTOM_AREA_PROPORTION = 0.044 -- 4,4% of the frame height for inputs
local mainFrameHeight = 500
local mainFrameWidth = 500
if not _G["YippYappDataDisplayFrame"] then
local frame = CreateFrame("Frame", "YippYappDataDisplayFrame", UIParent, "BasicFrameTemplateWithInset")
-- Frame setup code...
_G["YippYappDataDisplayFrame"] = frame
frame:SetSize(mainFrameWidth, mainFrameHeight)
frame:SetPoint("CENTER")
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
frame.title = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
frame.title:SetPoint("LEFT", frame.TitleBg, "LEFT", 5, 0)
frame.title:SetText("YippYapp Guild Tools")
local professionsAreaHeight = mainFrameHeight * PROFESSION_AREA_PROPORTION
local blacklistAreaHeight = mainFrameHeight * BLACKLIST_AREA_PROPORTION
local bottomAreaHeight = mainFrameHeight * BOTTOM_AREA_PROPORTION
local inputAreaHeight = mainFrameHeight * (INPUT_AREA_PROPORTION)
-- Insert frame into UISpecialFrames to close with Escape
tinsert(UISpecialFrames, frame:GetName())
--professions
frame.professionsScrollFrame = CreateFrame("ScrollFrame", "$parentProfessionsScrollFrame", frame, "UIPanelScrollFrameTemplate")
frame.professionsScrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -30)
frame.professionsScrollFrame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -30, bottomAreaHeight + 4)
local professionsContent = CreateFrame("Frame", "$parentProfessionsContent", frame.professionsScrollFrame)
professionsContent:SetSize(frame:GetWidth() - 40, professionsAreaHeight -10)
frame.professionsScrollFrame:SetScrollChild(professionsContent)
frame.professionsScrollFrame:Hide() -- Initially hidden
--Blacklist
frame.blacklistScrollFrame = CreateFrame("ScrollFrame", "$parentBlacklistScrollFrame", frame, "UIPanelScrollFrameTemplate")
frame.blacklistScrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -30)
frame.blacklistScrollFrame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -30, inputAreaHeight + bottomAreaHeight + 4)
local blacklistContent = CreateFrame("Frame", nil, frame.blacklistScrollFrame)
blacklistContent:SetSize(frame:GetWidth() - 40, blacklistAreaHeight - 10)
frame.blacklistScrollFrame:SetScrollChild(blacklistContent)
frame.blacklistScrollFrame:Hide() -- Initially hidden
-- Reference content areas in the frame for easy access
frame.professionsContent = professionsContent
frame.blacklistContent = blacklistContent
-- Scroll Frame
-- local scrollFrame = CreateFrame("ScrollFrame", nil, frame, "UIPanelScrollFrameTemplate")
-- scrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -30)
-- scrollFrame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -30, 10)
-- local content = CreateFrame("Frame", nil, scrollFrame)
-- content:SetSize(scrollFrame:GetWidth(), scrollFrame:GetHeight()) -- Initial size
-- scrollFrame:SetScrollChild(content)
-- frame.content = content
-- Create content areas
--CreateContentAreas(frame)
-- Create tabs
CreateTabs(frame)
CreateBottomFrame(frame, bottomAreaHeight)
CreateInputArea(frame, inputAreaHeight, bottomAreaHeight)
Tab_OnClick(frame.tabs[1], frame)
_G["YippYappDataDisplayFrame"] = frame
end
return _G["YippYappDataDisplayFrame"]
end
function createHeader(parent, text, xPosition, yPosition)
local header = parent:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
header:SetPoint("TOPLEFT", parent, "TOPLEFT", xPosition, yPosition)
header:SetText(text)
return header
end
function createColumnText(parent, text, xPosition, yPosition, color)
local textLine = parent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
textLine:SetPoint("TOPLEFT", parent, "TOPLEFT", xPosition, yPosition)
if color then
text = string.format("|cFF%02x%02x%02x%s|r", color.r * 255, color.g * 255, color.b * 255, text)
end
textLine:SetText(text)
return textLine
end
function createHorizontalLine(parent, xStart, xEnd, yPosition)
local line = parent:CreateTexture(nil, "OVERLAY")
line:SetColorTexture(1, 1, 1, 0.5) -- Set color and alpha of the line; adjust as needed
line:SetPoint("TOPLEFT", parent, "TOPLEFT", xStart, yPosition)
line:SetPoint("TOPRIGHT", parent, "TOPLEFT", xEnd, yPosition)
line:SetHeight(1) -- Line thickness
return line
end
function UpdateProfessionsContent(guildMembersData)
local frame = _G["YippYappDataDisplayFrame"]
if not frame then
frame = CreateDisplayFrame()
end
-- Determine the active content area. For this example, we'll update the professionsContent.
local contentArea = frame.professionsContent
ClearDynamicContent(contentArea)
local spacing = 15
local initialYOffset = -20 -- Initial Y offset from the top of the content area
local nameColumnX = 10
local professionColumnX = 90
local lastUpdatedColumnX = 370
-- Ensure dynamicContentList is initialized
if not contentArea.dynamicContentList then
contentArea.dynamicContentList = {}
end
-- Headers
table.insert(contentArea.dynamicContentList, createHeader(contentArea, localeTable.name, nameColumnX, initialYOffset))
table.insert(contentArea.dynamicContentList, createHeader(contentArea, localeTable.professions, professionColumnX, initialYOffset))
table.insert(contentArea.dynamicContentList, createHeader(contentArea, localeTable.lastUpdated, lastUpdatedColumnX, initialYOffset))
-- Horizontal line under headers
table.insert(contentArea.dynamicContentList, createHorizontalLine(contentArea, 0, frame:GetWidth(), initialYOffset - 15))
local contentHeight = initialYOffset - 5 - spacing -- Start below the headers
for _, data in pairs(guildMembersData) do
if next(data.professions) ~= nil then
local professionsStrs = {}
for _, profession in ipairs(data.professions) do
if profession[2] and profession[2] ~= "" then -- Check if spellSubName is not empty
professionStr = string.format("%s - %s", profession[1] or "N/A", profession[2])
else
professionStr = profession[1] or "N/A"
end
table.insert(professionsStrs, professionStr)
end
local professionsLine = table.concat(professionsStrs, ", ")
local classColor = RAID_CLASS_COLORS[string.upper(data.class)]
--print("character: " .. data.name .. " " .. "last updated: " .. data.lastUpdated)
table.insert(contentArea.dynamicContentList, createColumnText(contentArea, data.name, nameColumnX, contentHeight, classColor))
table.insert(contentArea.dynamicContentList, createColumnText(contentArea, professionsLine, professionColumnX, contentHeight))
table.insert(contentArea.dynamicContentList, createColumnText(contentArea, data.lastUpdated or "N/A", lastUpdatedColumnX, contentHeight))
-- Draw a line after each entry and track it
table.insert(contentArea.dynamicContentList, createHorizontalLine(contentArea, 0, frame:GetWidth(), contentHeight - 12))
-- Increment contentHeight for the next entry
contentHeight = contentHeight - spacing
end
end
contentArea:SetSize(frame:GetWidth(), initialYOffset)
frame:Hide()
end
function UpdateBlacklistContent(blacklistData)
local frame = _G["YippYappDataDisplayFrame"]
if not frame then
frame = CreateDisplayFrame()
end
-- Determine the active content area. For this example, we'll update the blacklistContent.
local contentArea = frame.blacklistContent
ClearDynamicContent(contentArea)
local spacing = 15
local initialYOffset = -20 -- Initial Y offset from the top of the content area
local nameColumnX = 10
local reasonColumnX = 90
local lastUpdatedColumnX = 270
local formattedTime = GetTimeDifference(YippYappGuildTools_BlacklistDB.lastUpdated)
-- Ensure dynamicContentList is initialized
if not contentArea.dynamicContentList then
contentArea.dynamicContentList = {}
end
-- Headers
table.insert(contentArea.dynamicContentList, createHeader(contentArea, localeTable.blacklisted, nameColumnX, initialYOffset))
table.insert(contentArea.dynamicContentList, createHeader(contentArea, localeTable.reason, reasonColumnX, initialYOffset))
table.insert(contentArea.dynamicContentList, createHeader(contentArea, localeTable.lastUpdated .. ": " .. formattedTime, lastUpdatedColumnX, initialYOffset))
-- Horizontal line under headers
table.insert(contentArea.dynamicContentList, createHorizontalLine(contentArea, 0, frame:GetWidth(), initialYOffset - 15))
local contentHeight = initialYOffset - 5 - spacing -- Start below the headers
for characterName, characterData in pairs(blacklistData) do
if characterName ~= "lastUpdated" then
local classColor = RAID_CLASS_COLORS[string.upper(characterData.class)]
table.insert(contentArea.dynamicContentList, createColumnText(contentArea, characterName, nameColumnX, contentHeight, classColor))
table.insert(contentArea.dynamicContentList, createColumnText(contentArea, characterData.reason, reasonColumnX, contentHeight))
-- Creating a horizontal line
table.insert(contentArea.dynamicContentList, createHorizontalLine(contentArea, 0, frame:GetWidth(), contentHeight - 12))
contentHeight = contentHeight - spacing -- Updated to include text height
end
end
contentArea:SetSize(frame:GetWidth(), initialYOffset)
frame:Hide()
end