Mercurial > wow > wowdb-profiler
comparison Comments.lua @ 275:ac6163ed8330
Resolve unit details while building the comment subject menu so units which are no longer valid afterward can still be commented on while the menu is up.
author | James D. Callahan III <jcallahan@curse.com> |
---|---|
date | Tue, 26 Mar 2013 22:57:18 -0500 |
parents | e9670d6c6bf1 |
children | a43a9444659e |
comparison
equal
deleted
inserted
replaced
274:431cf8672ca8 | 275:ac6163ed8330 |
---|---|
74 | 74 |
75 -- VARIABLES ---------------------------------------------------------- | 75 -- VARIABLES ---------------------------------------------------------- |
76 | 76 |
77 local comment_subject = {} | 77 local comment_subject = {} |
78 local comment_frame | 78 local comment_frame |
79 local comment_units = {} | |
79 | 80 |
80 -- HELPERS ------------------------------------------------------------ | 81 -- HELPERS ------------------------------------------------------------ |
81 | 82 |
82 local function NewComment(type_name, label, id) | 83 local function NewComment(type_name, label, id) |
83 comment_subject.id = id | 84 comment_subject.id = id |
88 comment_frame.subject_data:SetFormattedText("(%s #%d)", type_name, id) | 89 comment_frame.subject_data:SetFormattedText("(%s #%d)", type_name, id) |
89 comment_frame.scroll_frame.edit_box:SetText("") | 90 comment_frame.scroll_frame.edit_box:SetText("") |
90 _G.ShowUIPanel(comment_frame) | 91 _G.ShowUIPanel(comment_frame) |
91 end | 92 end |
92 | 93 |
93 local function CreateUnitComment(unit_id) | 94 local function CreateUnitComment(unit_id, is_command) |
94 if not _G.UnitExists(unit_id) then | 95 local unit_type, unit_idnum |
95 WDP:Printf("Unit '%s' does not exist.", unit_id) | 96 |
96 return | 97 if is_command then |
97 end | 98 if not _G.UnitExists(unit_id) then |
98 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID(unit_id)) | 99 WDP:Printf("Unit '%s' does not exist.", unit_id) |
100 return | |
101 end | |
102 unit_type, unit_idnum = ParseGUID(_G.UnitGUID(unit_id)) | |
103 else | |
104 local unit_data = comment_units[unit_id] | |
105 | |
106 if not unit_data then | |
107 WDP:Printf("Unit '%s' does not exist.", unit_id) | |
108 return | |
109 end | |
110 unit_type = unit_data.type | |
111 unit_idnum = unit_data.idnum | |
112 end | |
99 | 113 |
100 if not unit_idnum then | 114 if not unit_idnum then |
101 WDP:Printf("Unable to determine unit from '%s'", unit_id) | 115 WDP:Printf("Unable to determine unit from '%s'", unit_id) |
102 return | 116 return |
103 end | 117 end |
104 local type_name = private.UNIT_TYPE_NAMES[unit_type + 1] | 118 local type_name = private.UNIT_TYPE_NAMES[unit_type + 1] |
105 local unit_name = _G.UnitName(unit_id) | 119 local unit_name = is_command and _G.UnitName(unit_id) or comment_units[unit_id].name |
120 | |
121 table.wipe(comment_units) | |
106 NewComment(type_name, unit_name, unit_idnum) | 122 NewComment(type_name, unit_name, unit_idnum) |
107 end | 123 end |
108 | 124 |
109 local DATA_TYPE_MAPPING = { | 125 local DATA_TYPE_MAPPING = { |
110 merchant = "ITEM", | 126 merchant = "ITEM", |
248 local line | 264 local line |
249 | 265 |
250 for unit_id in pairs(VALID_UNITS) do | 266 for unit_id in pairs(VALID_UNITS) do |
251 if _G.UnitExists(unit_id) then | 267 if _G.UnitExists(unit_id) then |
252 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID(unit_id)) | 268 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID(unit_id)) |
269 local unit_name = _G.UnitName(unit_id) | |
253 | 270 |
254 if unit_idnum then | 271 if unit_idnum then |
255 line = display:AddLine(("%s: %s"):format(unit_id:gsub("^%l", _G.string.upper), _G.UnitName(unit_id))) | 272 comment_units[unit_id] = { |
273 idnum = unit_idnum, | |
274 name = unit_name, | |
275 type = unit_type, | |
276 } | |
277 line = display:AddLine(("%s: %s"):format(unit_id:gsub("^%l", _G.string.upper), unit_name)) | |
256 display:SetLineScript(line, "OnMouseUp", CreateComment, { CreateUnitComment, unit_id }) | 278 display:SetLineScript(line, "OnMouseUp", CreateComment, { CreateUnitComment, unit_id }) |
257 end | 279 end |
258 end | 280 end |
259 end | 281 end |
260 | 282 |
313 return | 335 return |
314 elseif arg == "quest" then | 336 elseif arg == "quest" then |
315 CreateQuestComment() | 337 CreateQuestComment() |
316 return | 338 return |
317 end | 339 end |
318 CreateUnitComment(arg) | 340 CreateUnitComment(arg, true) |
319 end | 341 end |
320 | 342 |
321 function private.InitializeCommentSystem() | 343 function private.InitializeCommentSystem() |
322 local panel = _G.CreateFrame("Frame", "WDP_CommentFrame", _G.UIParent, "TranslucentFrameTemplate") | 344 local panel = _G.CreateFrame("Frame", "WDP_CommentFrame", _G.UIParent, "TranslucentFrameTemplate") |
323 panel:SetSize(480, 350) | 345 panel:SetSize(480, 350) |
532 edit_box:SetText("") | 554 edit_box:SetText("") |
533 _G.HideUIPanel(panel) | 555 _G.HideUIPanel(panel) |
534 end) | 556 end) |
535 panel.submitButton = submit | 557 panel.submitButton = submit |
536 | 558 |
537 -- local data_obj = LibStub("LibDataBroker-1.1"):NewDataObject(ADDON_NAME, { | 559 -- local data_obj = LibStub("LibDataBroker-1.1"):NewDataObject(ADDON_NAME, { |
538 -- type = "data source", | 560 -- type = "data source", |
539 -- label = ADDON_NAME, | 561 -- label = ADDON_NAME, |
540 -- text = " ", | 562 -- text = " ", |
541 -- icon = [[Interface\CHATFRAME\UI-ChatIcon-Chat-Up]], | 563 -- icon = [[Interface\CHATFRAME\UI-ChatIcon-Chat-Up]], |
542 -- OnClick = function(self, button, down) | 564 -- OnClick = function(self, button, down) |
543 -- ShowPossibleSubjects(self) | 565 -- ShowPossibleSubjects(self) |
544 -- end, | 566 -- end, |
545 -- OnTooltipShow = function(self) | 567 -- OnTooltipShow = function(self) |
546 -- self:AddLine(_G.CLICK_TO_ENTER_COMMENT) | 568 -- self:AddLine(_G.CLICK_TO_ENTER_COMMENT) |
547 -- end, | 569 -- end, |
548 -- }) | 570 -- }) |
549 -- | 571 -- |
550 -- private.data_obj = data_obj | 572 -- private.data_obj = data_obj |
551 -- LibStub("LibDBIcon-1.0"):Register(ADDON_NAME, data_obj, private.db.global.config.minimap_icon) | 573 -- LibStub("LibDBIcon-1.0"):Register(ADDON_NAME, data_obj, private.db.global.config.minimap_icon) |
552 | 574 |
553 _G["BINDING_HEADER_WOWDB_PROFILER"] = "WoWDB Profiler" | 575 _G["BINDING_HEADER_WOWDB_PROFILER"] = "WoWDB Profiler" |
554 end | 576 end |