Mercurial > wow > wowdb-profiler
comparison Comments.lua @ 260:3558ba83eacd
Added comment support for cursor types: item, merchant (which maps to item), spell.
author | James D. Callahan III <jcallahan@curse.com> |
---|---|
date | Mon, 18 Mar 2013 17:58:08 -0500 |
parents | eac4dc8f462e |
children | 2f493bc054e5 |
comparison
equal
deleted
inserted
replaced
259:eac4dc8f462e | 260:3558ba83eacd |
---|---|
11 local LibStub = _G.LibStub | 11 local LibStub = _G.LibStub |
12 local WDP = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME) | 12 local WDP = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME) |
13 local Dialog = LibStub("LibDialog-1.0") | 13 local Dialog = LibStub("LibDialog-1.0") |
14 | 14 |
15 local ParseGUID = private.ParseGUID | 15 local ParseGUID = private.ParseGUID |
16 local ItemLinkToID = private.ItemLinkToID | |
16 | 17 |
17 -- CONSTANTS ---------------------------------------------------------- | 18 -- CONSTANTS ---------------------------------------------------------- |
18 | 19 |
19 local EDIT_MAXCHARS = 3000 | 20 local EDIT_MAXCHARS = 3000 |
20 local EDIT_DESCRIPTION_FORMAT = "Enter your comment below, being as descriptive as possible. Comments are limited to %s characters, including newlines and spaces." | 21 local EDIT_DESCRIPTION_FORMAT = "Enter your comment below, being as descriptive as possible. Comments are limited to %s characters, including newlines and spaces." |
25 | 26 |
26 local URL_TYPE_MAP = { | 27 local URL_TYPE_MAP = { |
27 ITEM = "items", | 28 ITEM = "items", |
28 OBJECT = "objects", | 29 OBJECT = "objects", |
29 NPC = "npcs", | 30 NPC = "npcs", |
31 SPELL = "spells", | |
30 VEHICLE = "npcs", | 32 VEHICLE = "npcs", |
31 } | 33 } |
32 | 34 |
33 Dialog:Register("WDP_CommentLink", { | 35 Dialog:Register("WDP_CommentLink", { |
34 text = "", | 36 text = "", |
258 _G.HideUIPanel(panel) | 260 _G.HideUIPanel(panel) |
259 end) | 261 end) |
260 panel.submitButton = submit | 262 panel.submitButton = submit |
261 end | 263 end |
262 | 264 |
263 local function CreateUnitComment(unit_id, unit_type, unit_idnum) | 265 local function CreateUnitComment(unit_id) |
266 if not _G.UnitExists(unit_id) then | |
267 WDP:Printf("Unit '%s' does not exist.", unit_id) | |
268 return | |
269 end | |
270 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID(unit_id)) | |
271 | |
272 if not unit_idnum then | |
273 WDP:Printf("Unable to determine unit from '%s'", unit_id) | |
274 return | |
275 end | |
264 local type_name = private.UNIT_TYPE_NAMES[unit_type + 1] | 276 local type_name = private.UNIT_TYPE_NAMES[unit_type + 1] |
265 local unit_name = _G.UnitName(unit_id) | 277 local unit_name = _G.UnitName(unit_id) |
266 | |
267 comment_subject.type_name = type_name | 278 comment_subject.type_name = type_name |
268 comment_subject.id = unit_idnum | 279 comment_subject.id = unit_idnum |
269 comment_subject.label = unit_name | 280 comment_subject.label = unit_name |
270 | 281 |
271 comment_frame.subject_name:SetText(unit_name) | 282 comment_frame.subject_name:SetText(unit_name) |
272 comment_frame.subject_data:SetFormattedText("(%s #%d)", type_name, unit_idnum) | 283 comment_frame.subject_data:SetFormattedText("(%s #%d)", type_name, unit_idnum) |
273 comment_frame.scroll_frame.edit_box:SetText("") | 284 comment_frame.scroll_frame.edit_box:SetText("") |
274 comment_frame:Show() | 285 comment_frame:Show() |
275 end | 286 end |
276 | 287 |
288 local DATA_TYPE_MAPPING = { | |
289 merchant = "ITEM", | |
290 } | |
291 | |
292 local CURSOR_DATA_FUNCS = { | |
293 item = function(data_type, data, data_subtype) | |
294 local item_name = _G.GetItemInfo(data) | |
295 comment_subject.type_name = data_type | |
296 comment_subject.id = data | |
297 comment_subject.label = item_name | |
298 | |
299 comment_frame.subject_name:SetText(item_name) | |
300 comment_frame.subject_data:SetFormattedText("(%s #%d)", data_type, data) | |
301 end, | |
302 merchant = function(data_type, data) | |
303 local item_link = _G.GetMerchantItemLink(data) | |
304 local item_name = _G.GetItemInfo(item_link) | |
305 local item_id = ItemLinkToID(item_link) | |
306 comment_subject.type_name = data_type | |
307 comment_subject.id = item_id | |
308 comment_subject.label = item_name | |
309 | |
310 comment_frame.subject_name:SetText(item_name) | |
311 comment_frame.subject_data:SetFormattedText("(%s #%d)", data_type, item_id) | |
312 end, | |
313 spell = function(data_type, data, data_subtype, subdata) | |
314 local spell_name = _G.GetSpellInfo(subdata) | |
315 comment_subject.type_name = data_type | |
316 comment_subject.id = subdata | |
317 comment_subject.label = spell_name | |
318 | |
319 comment_frame.subject_name:SetText(spell_name) | |
320 comment_frame.subject_data:SetFormattedText("(%s #%d)", data_type, subdata) | |
321 end, | |
322 } | |
323 | |
277 local function CreateCursorComment() | 324 local function CreateCursorComment() |
278 -- TODO: Implement! | 325 local data_type, data, data_subtype, subdata = _G.GetCursorInfo() |
326 | |
327 if not CURSOR_DATA_FUNCS[data_type] then | |
328 WDP:Print("Unable to determine comment subject from cursor.") | |
329 return | |
330 end | |
331 CURSOR_DATA_FUNCS[data_type](DATA_TYPE_MAPPING[data_type] or data_type:upper(), data, data_subtype, subdata) | |
332 comment_frame.scroll_frame.edit_box:SetText("") | |
333 comment_frame:Show() | |
279 end | 334 end |
280 | 335 |
281 -- METHODS ------------------------------------------------------------ | 336 -- METHODS ------------------------------------------------------------ |
282 | 337 |
283 function private.ProcessCommentCommand(arg) | 338 function private.ProcessCommentCommand(arg) |
285 WDP:Print("You must supply a valid comment type.") | 340 WDP:Print("You must supply a valid comment type.") |
286 return | 341 return |
287 end | 342 end |
288 | 343 |
289 if arg == "cursor" then | 344 if arg == "cursor" then |
290 WDP:Print("Not yet implemented.") | 345 CreateCursorComment() |
291 return | 346 return |
292 end | 347 end |
293 | 348 CreateUnitComment(arg) |
294 if not _G.UnitExists(arg) then | |
295 WDP:Printf("Unit '%s' does not exist.", arg) | |
296 return | |
297 end | |
298 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID(arg)) | |
299 | |
300 if not unit_idnum then | |
301 WDP:Printf("Unable to determine unit from '%s'", arg) | |
302 return | |
303 end | |
304 CreateUnitComment(arg, unit_type, unit_idnum) | |
305 end | 349 end |