-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrame.lua
370 lines (326 loc) · 16.6 KB
/
Frame.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
local addonName, addon = ...
local frame
local frameBaseHeight = 350
local frameBaseWidth = 275
local currentMapName
local entryLevelEditBox
local exitLevelEditBox
local monsterExperience
local restedExperience
local questExperience
local nodeExperience
local explorationExperience
local icons = {
{
["name"] = "Monsters",
["texture"] = 237272,
},
{
["name"] = "Rested",
["texture"] = 134414,
},
{
["name"] = "Quests",
["texture"] = 236669,
},
{
["name"] = "Nodes",
["texture"] = 133939,
},
{
["name"] = "Exploration",
["texture"] = 1032149,
},
}
local versionText
local resetButton
-- Refreshes the frame to update any values that may have changed
-- or need to change.
addon.RefreshFrame = function(mapID)
if frame and frame:IsVisible() then
currentMapName:SetText(addon.TruncateMapName(ExpBuddyDataDB[mapID].mapName))
entryLevelEditBox:SetText(tostring(ExpBuddyDataDB[mapID].entryLevel or 0))
exitLevelEditBox:SetText(tostring(ExpBuddyDataDB[mapID].exitLevel or 0))
monsterExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Monsters)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Monsters)))
restedExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Rested)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Rested)))
questExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Quests)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Quests)))
nodeExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Nodes)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Nodes)))
explorationExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Exploration)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Exploration)))
end
end
addon.LoadFrame = function()
-- If the frame is already visible, then hide it.
if frame then
if frame:IsVisible() then
frame:Hide()
return
end
end
-- Create the frame if it doesn't exist and set some standard attributes
-- for the frame.
if not frame then
frame = CreateFrame("Frame", addonName .. "Frame", UIParent, "BasicFrameTemplateWithInset")
frame:SetSize(frameBaseWidth, frameBaseHeight)
frame.TitleText:SetText(addonName)
end
-- If the player has opened the frame before and moved it, then use the
-- saved position for the new SetPoint, otherwise use the default.
if ExpBuddyPositionDB.SavedPosition then
frame:SetPoint(unpack(ExpBuddyPositionDB.SavedPosition))
else
frame:SetPoint("CENTER", UIParent, "CENTER")
end
-- Make the frame movable.
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function(self)
self:StartMoving()
end)
frame:SetScript("OnDragStop", function(self)
-- Once the frame stops moving, get the position data so we
-- can open the frame at that position next time.
self:StopMovingOrSizing()
local point, _, relativePoint, xOfs, yOfs = self:GetPoint()
ExpBuddyPositionDB.SavedPosition = { point, "UIParent", relativePoint, xOfs, yOfs }
end)
-- Create a font string for showing the current map name.
currentMapName = frame:CreateFontString(nil, nil, "GameFontNormal")
currentMapName:SetPoint("TOP", frame, "TOP", 0, -30)
currentMapName:SetText(addon.TruncateMapName(ExpBuddyDataDB[addon.mapID].mapName))
-- Create the entry level edit box.
entryLevelEditBox = CreateFrame("EditBox", addonName .. "EntryLevelEditBox", frame, "InputBoxTemplate")
entryLevelEditBox:SetAutoFocus(false)
entryLevelEditBox:SetSize(80, 10)
entryLevelEditBox:SetFontObject("ChatFontNormal")
entryLevelEditBox.title = entryLevelEditBox:CreateFontString(nil, nil, "GameTooltipText")
entryLevelEditBox.title:SetPoint("BOTTOMLEFT", entryLevelEditBox, "TOPLEFT", 0, 5)
entryLevelEditBox.title:SetText("Entry Level")
entryLevelEditBox:SetText(tostring(ExpBuddyDataDB[addon.mapID].entryLevel or 0))
entryLevelEditBox:SetScript("OnEnterPressed", function(self)
if tonumber(self:GetText(), 10) then
ExpBuddyDataDB[addon.mapID].entryLevel = tonumber(self:GetText(), 10)
self:SetText(ExpBuddyDataDB[addon.mapID].entryLevel)
self:ClearFocus()
else
ExpBuddy.Print("The value must be a number.")
end
end)
entryLevelEditBox:SetPoint("TOPLEFT", 15, -75)
-- Create the exit level edit box.
exitLevelEditBox = CreateFrame("EditBox", addonName .. "EntryLevelEditBox", frame, "InputBoxTemplate")
exitLevelEditBox:SetAutoFocus(false)
exitLevelEditBox:SetSize(80, 10)
exitLevelEditBox:SetFontObject("ChatFontNormal")
exitLevelEditBox.title = entryLevelEditBox:CreateFontString(nil, nil, "GameTooltipText")
exitLevelEditBox.title:SetPoint("BOTTOMLEFT", exitLevelEditBox, "TOPLEFT", 0, 5)
exitLevelEditBox.title:SetText("Exit Level")
exitLevelEditBox:SetText(tostring(ExpBuddyDataDB[addon.mapID].exitLevel or 0))
exitLevelEditBox:SetScript("OnEnterPressed", function(self)
if tonumber(self:GetText(), 10) then
ExpBuddyDataDB[addon.mapID].exitLevel = tonumber(self:GetText(), 10)
self:SetText(ExpBuddyDataDB[addon.mapID].exitLevel)
self:ClearFocus()
else
ExpBuddy.Print("The value must be a number.")
end
end)
exitLevelEditBox:SetPoint("TOPRIGHT", -15, -75)
-- Create the different category icons and labels in the frame.
for index, icon in ipairs(icons) do
local texture = frame:CreateTexture(addonName .. "FrameIcon" .. index, "BORDER")
if index == 1 then
texture:SetPoint("TOPLEFT", entryLevelEditBox, "BOTTOMLEFT", 0, -20)
else
texture:SetPoint("TOPLEFT", addonName .. "FrameIcon" .. (index - 1), "BOTTOMLEFT", 0, -15)
end
texture:SetSize(24, 24)
texture:SetTexture(icon.texture)
local iconLabel = frame:CreateFontString(nil, nil, "GameFontNormal")
iconLabel:SetPoint("LEFT", addonName .. "FrameIcon" .. index, "RIGHT", 5, 0)
iconLabel:SetText(icon.name)
local border = frame:CreateTexture(nil, "ARTWORK")
border:SetPoint("CENTER", texture, "CENTER", 0, 0)
border:SetSize(29, 29)
border:SetAtlas("Forge-ColorSwatchBorder", false)
end
-- Add in the font strings for the various experience values.
monsterExperience = frame:CreateFontString(nil, nil, "GameFontNormal")
monsterExperience:SetPoint("LEFT", addonName .. "FrameIcon" .. 1, "RIGHT", 80, 0)
monsterExperience:SetPoint("RIGHT", -15, 0)
monsterExperience:SetJustifyH("RIGHT")
monsterExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Monsters)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Monsters)))
restedExperience = frame:CreateFontString(nil, nil, "GameFontNormal")
restedExperience:SetPoint("LEFT", addonName .. "FrameIcon" .. 2, "RIGHT", 80, 0)
restedExperience:SetPoint("RIGHT", -15, 0)
restedExperience:SetJustifyH("RIGHT")
restedExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Rested)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Rested)))
questExperience = frame:CreateFontString(nil, nil, "GameFontNormal")
questExperience:SetPoint("LEFT", addonName .. "FrameIcon" .. 3, "RIGHT", 80, 0)
questExperience:SetPoint("RIGHT", -15, 0)
questExperience:SetJustifyH("RIGHT")
questExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Quests)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Quests)))
nodeExperience = frame:CreateFontString(nil, nil, "GameFontNormal")
nodeExperience:SetPoint("LEFT", addonName .. "FrameIcon" .. 4, "RIGHT", 80, 0)
nodeExperience:SetPoint("RIGHT", -15, 0)
nodeExperience:SetJustifyH("RIGHT")
nodeExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Nodes)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Nodes)))
explorationExperience = frame:CreateFontString(nil, nil, "GameFontNormal")
explorationExperience:SetPoint("LEFT", addonName .. "FrameIcon" .. 5, "RIGHT", 80, 0)
explorationExperience:SetPoint("RIGHT", -15, 0)
explorationExperience:SetJustifyH("RIGHT")
explorationExperience:SetText(format("|cffFFFFFF%s (%s%%)|r", tostring(addon.FormatNumber(ExpBuddyDataDB[addon.mapID].Exploration)), addon.CalculatePercent(ExpBuddyDataDB[addon.mapID].Exploration)))
versionText = frame:CreateFontString(nil, nil, "GameFontNormal")
versionText:SetPoint("BOTTOMLEFT", 15, 15)
versionText:SetText(C_AddOns.GetAddOnMetadata(addonName, "Version"))
resetButton = CreateFrame("Button", addonName .. "ResetButton", frame, "UIPanelButtonTemplate")
resetButton:SetSize(100, 25)
resetButton:RegisterForClicks("LeftButtonUp")
resetButton:SetText("Reset")
resetButton:SetScript("OnClick", function()
StaticPopupDialogs["EXPBUDDY_ACK_RESET"] = {
text = format("Are you sure you want to reset the data for %s?", ExpBuddyDataDB[addon.mapID].mapName),
button1 = YES,
button2 = NO,
OnAccept = function(self, data)
ExpBuddyDataDB[addon.mapID].Monsters = 0
ExpBuddyDataDB[addon.mapID].Rested = 0
ExpBuddyDataDB[addon.mapID].Quests = 0
ExpBuddyDataDB[addon.mapID].Nodes = 0
ExpBuddyDataDB[addon.mapID].Exploration = 0
addon.RefreshFrame(addon.mapID)
end,
showAlert = true,
whileDead = false,
hideOnEscape = true,
enterClicksFirstButton = false,
preferredIndex = 3,
}
StaticPopup_Show("EXPBUDDY_ACK_RESET")
end)
resetButton:SetPoint("BOTTOMRIGHT", -15, 15)
frame:Show()
end
--local AceGUI = LibStub("AceGUI-3.0")
--[[
-- AceGUI Widgets
local frame = AceGUI:Create("Frame")
addonTable.currentMapLabel = AceGUI:Create("Label")
addonTable.monstersLabel = AceGUI:Create("Label")
addonTable.restedLabel = AceGUI:Create("Label")
addonTable.questsLabel = AceGUI:Create("Label")
addonTable.nodesLabel = AceGUI:Create("Label")
addonTable.explorationLabel = AceGUI:Create("Label")
addonTable.resetButton = AceGUI:Create("Button")
-- Hide the frame from view since the Create function
-- automatically shows it. :(
frame:Hide()
ExpBuddy = LibStub("AceAddon-3.0"):NewAddon("ExpBuddy", "AceConsole-3.0")
function ExpBuddy:SlashCommandHandler(cmd)
local cmd, arg1 = string.split(" ", cmd)
if not cmd or cmd == "" then
Settings.OpenToCategory(addonName)
elseif cmd == "tracker" then
if frame:IsVisible() == false then
-- I guess I need to recreate the frame since it's been hidden
-- (see top of file).
frame = AceGUI:Create("Frame")
-- Also, since the frame was hidden I need to recreate the children.
-- They're created twice because the labels are referenced in ExpBuddy.lua.
addonTable.currentMapLabel = AceGUI:Create("Label")
addonTable.monstersLabel = AceGUI:Create("Label")
addonTable.restedLabel = AceGUI:Create("Label")
addonTable.questsLabel = AceGUI:Create("Label")
addonTable.nodesLabel = AceGUI:Create("Label")
addonTable.explorationLabel = AceGUI:Create("Label")
addonTable.resetButton = AceGUI:Create("Button")
-- Set some attributes for the frame.
frame:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end)
frame:SetTitle("ExpBuddy")
frame:SetStatusText(C_AddOns.GetAddOnMetadata(addonName, "Version"))
frame:SetLayout("List")
frame:EnableResize(false)
frame:SetWidth(215)
frame:SetHeight(350)
-- Get all the labels' data.
local labels = addonTable.GetData()
-- All widgets are created in Data\Constants.lua.
-- Current Zone Label
addonTable.currentMapLabel:SetText("|cffFFD100" .. "Current Map|r: " .. addonTable.Substring(addonTable.currentMap))
frame:AddChild(addonTable.currentMapLabel)
-- Monsters Label
local monstersXP = addonTable.FormatNumber(tostring(labels.Monsters))
addonTable.monstersLabel:SetText("\n\n" .. CreateAtlasMarkup("ShipMission_DangerousSkull", 16, 16) .. " |cffFFD100" .. "Monsters|r: " .. monstersXP .. " (" .. addonTable.CalculatePercent(labels.Monsters) .. "%)")
frame:AddChild(addonTable.monstersLabel)
-- Rested XP Label
local restedXP = addonTable.FormatNumber(tostring(labels.Rested))
addonTable.restedLabel:SetText("\n" .. CreateAtlasMarkup("Gamepad_Rev_Home_64", 16, 16) .. " |cffFFD100" .. "Rested|r: " .. restedXP .. " (" .. addonTable.CalculatePercent(labels.Rested) .. "%)")
frame:AddChild(addonTable.restedLabel)
-- Quests Label
local questsXP = addonTable.FormatNumber(tostring(labels.Quests))
addonTable.questsLabel:SetText("\n" .. CreateAtlasMarkup("NPE_TurnIn", 16, 16) .. " |cffFFD100" .. "Quests|r: " .. questsXP .. " (" .. addonTable.CalculatePercent(labels.Quests) .. "%)")
frame:AddChild(addonTable.questsLabel)
-- Nodes Label
local nodesXP = addonTable.FormatNumber(tostring(labels.Nodes))
addonTable.nodesLabel:SetText("\n" .. CreateAtlasMarkup("Mobile-TreasureIcon", 16, 16) .. " |cffFFD100" .. "Nodes|r: " .. nodesXP .. " (" .. addonTable.CalculatePercent(labels.Nodes) .. "%)")
frame:AddChild(addonTable.nodesLabel)
-- Exploration Label
local explorationXP = addonTable.FormatNumber(tostring(labels.Exploration))
addonTable.explorationLabel:SetText("\n" .. CreateAtlasMarkup("GarrMission_MissionIcon-Exploration", 16, 16) .. " |cffFFD100" .. "Exploration|r: " .. explorationXP .. " (" .. addonTable.CalculatePercent(labels.Exploration) .. "%)\n\n")
frame:AddChild(addonTable.explorationLabel)
-- Reset Button
addonTable.resetButton:SetText("Reset")
addonTable.resetButton:SetWidth(100)
addonTable.resetButton:SetCallback("OnClick", function(widget, event, text)
local labels = addonTable.GetData()
if (labels.Monsters+labels.Rested+labels.Quests+labels.Nodes+labels.Exploration) == 0 then
print(addonTable.data["COLORED_ADDON_NAME"] .. ": This zone doesn't have any data to reset.")
else
end
end)
frame:AddChild(addonTable.resetButton)
else
-- The frame and its children should be released to the widget
-- pool on close. This is triggered if the frame is shown and
-- the player re-enters the /xp tracker command.
AceGUI:Release(frame)
end
elseif cmd == "search" and arg1 ~= nil then
-- Make a local variable and copy the saved variable to it. We want
-- the temporary table to sort alphabetically by map name.
local maps = {}
for k, v in pairs(ExpBuddyDataDB) do
table.insert(maps, { ["name"] = k, ["map"] = v })
end
table.sort(maps, function(a, b)
return string.lower(a.name) < string.lower(b.name)
end)
local str = string.lower(arg1)
for _, data in ipairs(maps) do
if str == "*" then
-- Return every map's data.
print("|cffFFD100" .. data.name .. "|r:" .. "\n" ..
"|cffFFD100" .. "Monsters|r: " .. addonTable.FormatNumber(tostring(data.map.Monsters)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Monsters) .. "%)|r" .. "\n" ..
"|cffFFD100" .. "Rested|r: " .. addonTable.FormatNumber(tostring(data.map.Rested)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Rested) .. "%)|r" .. "\n" ..
"|cffFFD100" .. "Quests|r: " .. addonTable.FormatNumber(tostring(data.map.Quests)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Quests) .. "%)|r" .. "\n" ..
"|cffFFD100" .. "Nodes|r: " .. addonTable.FormatNumber(tostring(data.map.Nodes)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Nodes) .. "%)|r" .. "\n" ..
"|cffFFD100" .. "Exploration|r: " .. addonTable.FormatNumber(tostring(data.map.Exploration)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Exploration) .. "%)|r"
)
elseif string.find(string.lower(data.name), str) then
-- We have a match, so print the data!
print("|cffFFD100" .. data.name .. "|r:" .. "\n" ..
"|cffFFD100" .. "Monsters|r: " .. addonTable.FormatNumber(tostring(data.map.Monsters)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Monsters) .. "%)|r" .. "\n" ..
"|cffFFD100" .. "Rested|r: " .. addonTable.FormatNumber(tostring(data.map.Rested)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Rested) .. "%)|r" .. "\n" ..
"|cffFFD100" .. "Quests|r: " .. addonTable.FormatNumber(tostring(data.map.Quests)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Quests) .. "%)|r" .. "\n" ..
"|cffFFD100" .. "Nodes|r: " .. addonTable.FormatNumber(tostring(data.map.Nodes)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Nodes) .. "%)|r" .. "\n" ..
"|cffFFD100" .. "Exploration|r: " .. addonTable.FormatNumber(tostring(data.map.Exploration)) .. " |cffADD8E6(" .. addonTable.CalculatePercent(data.map.Exploration) .. "%)|r"
)
end
end
end
end
function ExpBuddy:OnInitialize()
LibStub("AceConfig-3.0"):RegisterOptionsTable("ExpBuddy_Main", addonTable.mainOptions)
self.mainOptions = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ExpBuddy_Main", addonName); addonTable.mainOptions = self.mainOptions
self:RegisterChatCommand("xp", "SlashCommandHandler")
end]]