comparison Comments.lua @ 259:eac4dc8f462e

Added support for opening a page link in a dialog so users can copy/paste the URL for comments on their comment subject.
author James D. Callahan III <jcallahan@curse.com>
date Mon, 18 Mar 2013 15:12:05 -0500
parents 88d2c426f876
children 3558ba83eacd
comparison
equal deleted inserted replaced
258:88d2c426f876 259:eac4dc8f462e
8 8
9 local ADDON_NAME, private = ... 9 local ADDON_NAME, private = ...
10 10
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 14
14 local ParseGUID = private.ParseGUID 15 local ParseGUID = private.ParseGUID
15 16
16 -- CONSTANTS ---------------------------------------------------------- 17 -- CONSTANTS ----------------------------------------------------------
17 18
18 local EDIT_MAXCHARS = 3000 19 local EDIT_MAXCHARS = 3000
19 local EDIT_DESCRIPTION_FORMAT = [[Enter your comment below, being as descriptive as possible. Comments are limited to %s characters, including newlines and spaces.]] 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 LINK_COMMENT_TOOLTIP = "Click here to create a link to the comment page on WoWDB."
22 local LINK_EDITBOX_DESC_FORMAT = "Copy the highlighted text and paste it into your browser to visit the comments for %s."
23
24 local URL_BASE = "http://www.wowdb.com/"
25
26 local URL_TYPE_MAP = {
27 ITEM = "items",
28 OBJECT = "objects",
29 NPC = "npcs",
30 VEHICLE = "npcs",
31 }
32
33 Dialog:Register("WDP_CommentLink", {
34 text = "",
35 editboxes = {
36 {
37 text = _G.UNKNOWN,
38 on_escape_pressed = function(self)
39 self:ClearFocus()
40 end,
41 },
42 },
43 buttons = {
44 {
45 text = _G.OKAY,
46 }
47 },
48 show_while_dead = true,
49 hide_on_escape = true,
50 is_exclusive = true,
51 on_show = function(self, data)
52 local editbox = self.editboxes[1]
53 editbox:SetWidth(self:GetWidth() - 20)
54 editbox:SetText(("%s%s/%d#related:comments"):format(URL_BASE, URL_TYPE_MAP[data.type_name], data.id))
55 editbox:HighlightText()
56 editbox:SetFocus()
57
58 self.text:SetFormattedText(LINK_EDITBOX_DESC_FORMAT:format(data.label))
59 end,
60 })
61
62 local comment_subject = {}
20 63
21 -- HELPERS ------------------------------------------------------------ 64 -- HELPERS ------------------------------------------------------------
22 65
23 local comment_frame 66 local comment_frame
24 do 67 do
114 }) 157 })
115 158
116 edit_container:SetBackdropBorderColor(_G.TOOLTIP_DEFAULT_COLOR.r, _G.TOOLTIP_DEFAULT_COLOR.g, _G.TOOLTIP_DEFAULT_COLOR.b) 159 edit_container:SetBackdropBorderColor(_G.TOOLTIP_DEFAULT_COLOR.r, _G.TOOLTIP_DEFAULT_COLOR.g, _G.TOOLTIP_DEFAULT_COLOR.b)
117 edit_container:SetBackdropColor(0, 0, 0) 160 edit_container:SetBackdropColor(0, 0, 0)
118 161
162 local link_button = _G.CreateFrame("Button", "$parentLinkButton", panel)
163 link_button:SetSize(32, 16)
164 link_button:SetPoint("TOPRIGHT", edit_container, "BOTTOMRIGHT", 5, 0)
165
166 link_button:SetNormalTexture([[Interface\TradeSkillFrame\UI-TradeSkill-LinkButton]])
167 link_button:GetNormalTexture():SetTexCoord(0, 1, 0, 0.5)
168
169 link_button:SetHighlightTexture([[Interface\TradeSkillFrame\UI-TradeSkill-LinkButton]])
170 link_button:GetHighlightTexture():SetTexCoord(0, 1, 0.5, 1)
171
172 link_button:SetScript("OnClick", function(self)
173 Dialog:Spawn("WDP_CommentLink", { type_name = comment_subject.type_name, id = comment_subject.id, label = comment_subject.label })
174 end)
175
176 link_button:SetScript("OnEnter", function(self)
177 _G.GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT")
178 _G.GameTooltip:SetText(LINK_COMMENT_TOOLTIP, nil, nil, nil, nil, 1)
179 _G.GameTooltip:Show()
180 end)
181
182 link_button:SetScript("OnLeave", _G.GameTooltip_Hide)
183
119 local edit_description = edit_container:CreateFontString("MUFASA", "ARTWORK", "GameFontHighlight") 184 local edit_description = edit_container:CreateFontString("MUFASA", "ARTWORK", "GameFontHighlight")
120 edit_description:SetHeight(36) 185 edit_description:SetHeight(36)
121 edit_description:SetPoint("BOTTOMLEFT", edit_container, "TOPLEFT", 5, 3) 186 edit_description:SetPoint("BOTTOMLEFT", edit_container, "TOPLEFT", 5, 3)
122 edit_description:SetPoint("BOTTOMRIGHT", edit_container, "TOPRIGHT", 5, 3) 187 edit_description:SetPoint("BOTTOMRIGHT", edit_container, "TOPRIGHT", 5, 3)
123 edit_description:SetFormattedText(EDIT_DESCRIPTION_FORMAT, _G.BreakUpLargeNumbers(EDIT_MAXCHARS)) 188 edit_description:SetFormattedText(EDIT_DESCRIPTION_FORMAT, _G.BreakUpLargeNumbers(EDIT_MAXCHARS))
194 end) 259 end)
195 panel.submitButton = submit 260 panel.submitButton = submit
196 end 261 end
197 262
198 local function CreateUnitComment(unit_id, unit_type, unit_idnum) 263 local function CreateUnitComment(unit_id, unit_type, unit_idnum)
199 comment_frame.subject_name:SetText(_G.UnitName(unit_id)) 264 local type_name = private.UNIT_TYPE_NAMES[unit_type + 1]
200 comment_frame.subject_data:SetFormattedText("(%s #%d)", private.UNIT_TYPE_NAMES[unit_type + 1], unit_idnum) 265 local unit_name = _G.UnitName(unit_id)
266
267 comment_subject.type_name = type_name
268 comment_subject.id = unit_idnum
269 comment_subject.label = unit_name
270
271 comment_frame.subject_name:SetText(unit_name)
272 comment_frame.subject_data:SetFormattedText("(%s #%d)", type_name, unit_idnum)
201 comment_frame.scroll_frame.edit_box:SetText("") 273 comment_frame.scroll_frame.edit_box:SetText("")
202 comment_frame:Show() 274 comment_frame:Show()
203 end 275 end
204 276
205 local function CreateCursorComment() 277 local function CreateCursorComment()