-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMM_LDB.lua
More file actions
295 lines (267 loc) · 8.42 KB
/
MM_LDB.lua
File metadata and controls
295 lines (267 loc) · 8.42 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
--[[
**********************************************************************
MagicMarker - your best friend for raid marking. See README.txt for
more details.
**********************************************************************
This file is part of MagicMarker, a World of Warcraft Addon
MagicMarker is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MagicMarker is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with MagicMarker. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************
]]
local mod = LibStub("AceAddon-3.0"):GetAddon("MagicMarker")
local L = LibStub("AceLocale-3.0"):GetLocale("MagicMarker", false)
local C = LibStub("AceConfigDialog-3.0")
local LD = LibStub("LibDropdown-1.0", true)
local QTIP = LibStub("LibQTip-1.0")
local DBOpt = LibStub("AceDBOptions-3.0")
local tinsert = tinsert
local sort = table.sort
local fmt = string.format
local db, tooltip
local MMDB
local function white(str)
return fmt("|cffffffff%s|r", str)
end
local function yellow(str)
return fmt("|cffffff00%s|r", str)
end
local markedTargets, totalTargets
-- Options for the dropdown menu, partially populated by magic marker config data
local options = {
type = "group",
handler = mod,
set = "SetProfileParam",
get = "GetProfileParam",
args = {
config = {
type = "execute",
name = L["Toggle config dialog"],
desc = L["Toggle the Magic Marker configuration dialog."],
func = "ToggleConfigDialog",
order = 1
},
toggle = {
type = "toggle",
name = L["Toggle event handling"],
desc = L["Enable or disable the event handling, i.e whether or not Magic Marker will insert mobs into the mob database, mark mobs etc."],
set = "ToggleMagicMarker",
get = function() return mod.addonEnabled end,
order = 2
},
assignments = {
type = "execute",
name = L["Report raid assignments"],
desc = L["Report the raid icon assignments to raid/party chat"]..".",
func = "ReportRaidMarks",
},
reset = {
type = "execute",
name = L["Reset raid icon cache"],
desc = L["Reset the raid icon cache. Note that this honors the Magic Marker options such as preserve raid marks."],
func = "ResetMarkData",
},
commsettings = {
type = "group",
name = L["Data Sharing"],
desc = L["Data Sharing"],
order = 1200,
args = {}
},
settings = {
type = "group",
name = L["General Options"],
desc = L["General Options"],
order = 1100,
args = {}
},
profiledata = {
type = "group",
name = "Profile",
desc = "Profile",
order = 1300,
args = {}
},
cache = {
type = "group",
name = L["Raid mark layout caching"],
desc = L["RAIDMARKCACHEHELP"],
order = 1000,
args = {
save = {
type = "execute",
name = L["Save party/raid mark layout"],
desc = L["Save the current raid mark layout."],
func = "CacheRaidMarks",
},
load = {
type = "execute",
name = L["Load party/raid mark layout"],
desc = L["Load the currently saved raid mark layout."],
func = "MarkRaidFromCache",
},
}
},
}
}
function mod:SetupLDB()
local LDB = LibStub("LibDataBroker-1.1", true)
if not LDB then return end
if LDB then
mod.ldb =
LDB:NewDataObject("Magic Marker",
{
type = "data source",
label = L["Magic Marker"],
icon = [[Interface\Addons\MagicMarker\icon]],
OnClick = function(clickedframe, button)
if button == "LeftButton" then
if IsAltKeyDown() then
mod:ResetMarkData(IsShiftKeyDown())
elseif IsShiftKeyDown() then
mod:ToggleMagicMarker()
else
mod:ToggleConfigDialog()
end
elseif button == "MiddleButton" then
mod:ReportRaidMarks()
elseif button == "RightButton" then
-- create the menu
if LD then
local frame = LD:OpenAce3Menu(options)
-- Anchor the menu to the mouse
frame:SetPoint("TOPLEFT", clickedframe, "BOTTOMLEFT", 0, 0)
frame:SetFrameLevel(clickedframe:GetFrameLevel()+100)
end
end
end,
OnEnter = function(frame) mod:OnLDBEnter(frame) end,
OnLeave = function(frame) if tooltip then QTIP:Release(tooltip) tooltip = nil end end,
})
end
mod:UpdateLDBConfig()
mod:UpdateLDBLabel()
end
function mod:UpdateLDB()
mod:UpdateLDBLabel()
if tooltip then
mod:OnLDBEnter()
end
end
function mod:UpdateLDBConfig()
db = mod.db.profile
MMDB = MagicMarkerDB
local mmopts = mod:GetOptions()
options.args.commsettings.args = mmopts.args.options.args.commsettings.args
options.args.settings.args = mmopts.args.options.args.settings.args
if mmopts.args.options.args.profile then
options.args.profiledata.args = mmopts.args.options.args.profile.args
options.args.profiledata.name = mmopts.args.options.args.profile.name
options.args.profiledata.desc = mmopts.args.options.args.profile.desc
options.args.profiledata.handler = mmopts.args.options.args.profile.handler
end
end
optionsdump = options
function mod:SetTargetCount(marked, total)
markedTargets = marked
totalTargets = total
self:UpdateLDB()
end
function mod:UpdateLDBLabel()
local str = white((mod.addonEnabled and L["Enabled"]) or L["Disabled"])
if totalTargets and totalTargets > 0 then
str = string.format("%s (%d/%d)", str, markedTargets, totalTargets)
end
mod.ldb.text = str
end
local function _n(text)
return fmt("|cffffd200%s|r", text)
end
function mod:OnLDBEnter(frame)
local y
local zone = GetRealZoneText()
local sortData = {}
local hasData
local cacheData = mod:GetMarkData()
local valueToId = {}
if not tooltip then
tooltip = QTIP:Acquire("MagicMarkerLDBTooltip")
tooltip:SetColumnLayout(4, "LEFT", "CENTER", "CENTER", "CENTER")
else
tooltip:Clear()
end
-- Set up the mark data to be sorted, and see if we have data
for id, data in pairs(cacheData) do
if data.value then
local key = data.value * 10000 + id
valueToId[key] = id
tinsert(sortData,key )
hasData = true
end
end
y = tooltip:AddLine( _n(L["Status"]));
tooltip:SetCell(y, 2, mod.addonEnabled and L["Enabled"] or L["Disabled"], nil, "RIGHT", 3)
y = tooltip:AddLine( _n(L["Zone"]))
tooltip:SetCell(y, 2, zone, nil, "RIGHT", 3)
local zoneID, _, heroic = mod:GetZoneName(zone)
local inInstance, type = IsInInstance()
if inInstance then
local difficulty, difftext = mod:GetDifficultyInfo()
y = tooltip:AddLine( _n(L["Difficulty"]));
tooltip:SetCell(y, 2, difftext, nil, "RIGHT", 3)
end
if MMDB.mobdata[zoneID] then
tooltip:AddLine(" ")
y = tooltip:AddLine()
tooltip:SetCell(y, 1, _n(mod:GetZoneInfo(MMDB.mobdata[zoneID])), nil, "LEFT", 4)
end
totalTargets = 0
markedTargets = 0
if hasData then
tooltip:AddLine(" ")
sort(sortData, function(a,b) return a > b end)
tooltip:AddLine( yellow(L["Unit Name"]),
yellow(L["Mark Type"]),
yellow(L["Score"]),
yellow(L["Marked"]))
tooltip:AddSeparator()
local data
for _, id in pairs(sortData) do
id = valueToId[id]
data = cacheData[id]
if data.uid then
local valid
totalTargets = totalTargets + 1
if data.valid == nil then
valid = "N/A"
markedTargets = markedTargets + 1
elseif data.valid then
markedTargets = markedTargets + 1
valid = L["Yes"]
else
valid = L["No"]
end
unitData = mod:GetUnitHash(data.uid)
tooltip:AddLine("|T"..mod:GetIconTexture(id)..":18|t".._n(unitData and unitData.name or data.uid),
_n(mod:GetCCName(data.ccid, data.value)),
_n(string.format("%2.2f", data.value)),
_n(valid))
end
end
end
tooltip:AddLine(" ")
local y = tooltip:AddLine()
tooltip:SetCell(y, 1, _n(L["TOOLTIP_HINT"]), nil, "LEFT", 4)
if frame then
tooltip:SmartAnchorTo(frame)
end
tooltip:UpdateScrolling()
tooltip:Show()
end