comparison Comments.lua @ 258:88d2c426f876

Add instructions as well as name and type/ID of comment subject to comment frame. Behavioral polish.
author James D. Callahan III <jcallahan@curse.com>
date Mon, 18 Mar 2013 13:45:21 -0500
parents 3fe3e55c327e
children eac4dc8f462e
comparison
equal deleted inserted replaced
257:834251607624 258:88d2c426f876
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 13
14 local ParseGUID = private.ParseGUID 14 local ParseGUID = private.ParseGUID
15
16 -- CONSTANTS ----------------------------------------------------------
17
18 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.]]
15 20
16 -- HELPERS ------------------------------------------------------------ 21 -- HELPERS ------------------------------------------------------------
17 22
18 local comment_frame 23 local comment_frame
19 do 24 do
20 local panel = _G.CreateFrame("Frame", "WDP_CommentFrame", _G.UIParent, "TranslucentFrameTemplate") 25 local panel = _G.CreateFrame("Frame", "WDP_CommentFrame", _G.UIParent, "TranslucentFrameTemplate")
21 panel:SetSize(480, 454) 26 panel:SetSize(480, 350)
22 panel:SetPoint("CENTER", _G.UIParent, "CENTER") 27 panel:SetPoint("CENTER", _G.UIParent, "CENTER")
23 panel:SetFrameStrata("DIALOG") 28 panel:SetFrameStrata("DIALOG")
24 panel.Bg:SetTexture([[Interface\FrameGeneral\UI-Background-Rock]], true, true) 29 panel.Bg:SetTexture([[Interface\FrameGeneral\UI-Background-Rock]], true, true)
25 panel.Bg:SetHorizTile(true) 30 panel.Bg:SetHorizTile(true)
26 panel.Bg:SetVertTile(true) 31 panel.Bg:SetVertTile(true)
32 local streaks = panel:CreateTexture("$parentTopTileStreaks", "BORDER", "_UI-Frame-TopTileStreaks", -6) 37 local streaks = panel:CreateTexture("$parentTopTileStreaks", "BORDER", "_UI-Frame-TopTileStreaks", -6)
33 streaks:SetPoint("TOPLEFT", 13, -13) 38 streaks:SetPoint("TOPLEFT", 13, -13)
34 streaks:SetPoint("BOTTOMRIGHT", panel, "TOPRIGHT", -13, -35) 39 streaks:SetPoint("BOTTOMRIGHT", panel, "TOPRIGHT", -13, -35)
35 40
36 local header = _G.CreateFrame("Frame", "$parentHeader", panel, "TranslucentFrameTemplate") 41 local header = _G.CreateFrame("Frame", "$parentHeader", panel, "TranslucentFrameTemplate")
37 -- header:SetSize(180, 45)
38 header:SetSize(128, 64) 42 header:SetSize(128, 64)
39 header:SetPoint("CENTER", panel, "TOP", 0, -8) 43 header:SetPoint("CENTER", panel, "TOP", 0, -8)
40 header.Bg:SetTexture([[Interface\FrameGeneral\UI-Background-Marble]]) 44 header.Bg:SetTexture([[Interface\FrameGeneral\UI-Background-Marble]])
41 header.Bg:SetHorizTile(true) 45 header.Bg:SetHorizTile(true)
42 header.Bg:SetVertTile(true) 46 header.Bg:SetVertTile(true)
45 local logo = header:CreateTexture(nil, "ARTWORK") 49 local logo = header:CreateTexture(nil, "ARTWORK")
46 logo:SetTexture([[Interface\AddOns\WoWDBProfiler\wowdb-logo]]) 50 logo:SetTexture([[Interface\AddOns\WoWDBProfiler\wowdb-logo]])
47 logo:SetPoint("TOPLEFT", header, 10, -10) 51 logo:SetPoint("TOPLEFT", header, 10, -10)
48 logo:SetPoint("BOTTOMRIGHT", header, -10, 10) 52 logo:SetPoint("BOTTOMRIGHT", header, -10, 10)
49 53
50 --[[ 54 local subject_name = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
51 local header_label = header:CreateFontString(nil, "ARTWORK", "GameFontNormal") 55 subject_name:SetPoint("TOP", header, "BOTTOM", 0, -10)
52 header_label:SetPoint("CENTER", 0, 0) 56 panel.subject_name = subject_name
53 header_label:SetText(ADDON_NAME) 57
54 ]] 58 local subject_data = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
59 subject_data:SetPoint("TOP", subject_name, "BOTTOM", 0, -3)
60 panel.subject_data = subject_data
55 61
56 local close = _G.CreateFrame("Button", nil, panel, "UIPanelCloseButton") 62 local close = _G.CreateFrame("Button", nil, panel, "UIPanelCloseButton")
57 close:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -7, -7) 63 close:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -7, -7)
58 64
59 local scroll_frame = _G.CreateFrame("ScrollFrame", "$parentScrollFrame", panel) 65 local scroll_frame = _G.CreateFrame("ScrollFrame", "$parentScrollFrame", panel)
84 end) 90 end)
85 91
86 scroll_frame:SetScript("OnMouseWheel", function(self, delta) 92 scroll_frame:SetScript("OnMouseWheel", function(self, delta)
87 _G.ScrollFrameTemplate_OnMouseWheel(self, delta) 93 _G.ScrollFrameTemplate_OnMouseWheel(self, delta)
88 end) 94 end)
95
96 panel.scroll_frame = scroll_frame
89 97
90 local edit_container = _G.CreateFrame("Frame", nil, scroll_frame) 98 local edit_container = _G.CreateFrame("Frame", nil, scroll_frame)
91 edit_container:SetPoint("TOPLEFT", scroll_frame, -7, 7) 99 edit_container:SetPoint("TOPLEFT", scroll_frame, -7, 7)
92 edit_container:SetPoint("BOTTOMRIGHT", scroll_frame, 7, -7) 100 edit_container:SetPoint("BOTTOMRIGHT", scroll_frame, 7, -7)
93 edit_container:SetFrameLevel(scroll_frame:GetFrameLevel() - 1) 101 edit_container:SetFrameLevel(scroll_frame:GetFrameLevel() - 1)
106 }) 114 })
107 115
108 edit_container:SetBackdropBorderColor(_G.TOOLTIP_DEFAULT_COLOR.r, _G.TOOLTIP_DEFAULT_COLOR.g, _G.TOOLTIP_DEFAULT_COLOR.b) 116 edit_container:SetBackdropBorderColor(_G.TOOLTIP_DEFAULT_COLOR.r, _G.TOOLTIP_DEFAULT_COLOR.g, _G.TOOLTIP_DEFAULT_COLOR.b)
109 edit_container:SetBackdropColor(0, 0, 0) 117 edit_container:SetBackdropColor(0, 0, 0)
110 118
119 local edit_description = edit_container:CreateFontString("MUFASA", "ARTWORK", "GameFontHighlight")
120 edit_description:SetHeight(36)
121 edit_description:SetPoint("BOTTOMLEFT", edit_container, "TOPLEFT", 5, 3)
122 edit_description:SetPoint("BOTTOMRIGHT", edit_container, "TOPRIGHT", 5, 3)
123 edit_description:SetFormattedText(EDIT_DESCRIPTION_FORMAT, _G.BreakUpLargeNumbers(EDIT_MAXCHARS))
124 edit_description:SetWordWrap(true)
125 edit_description:SetJustifyH("LEFT")
126
111 local edit_box = _G.CreateFrame("EditBox", nil, scroll_frame) 127 local edit_box = _G.CreateFrame("EditBox", nil, scroll_frame)
112 edit_box:SetMultiLine(true) 128 edit_box:SetMultiLine(true)
113 edit_box:SetMaxLetters(3000) 129 edit_box:SetMaxLetters(EDIT_MAXCHARS)
114 edit_box:EnableMouse(true) 130 edit_box:EnableMouse(true)
115 edit_box:SetAutoFocus(false) 131 edit_box:SetAutoFocus(false)
116 edit_box:SetFontObject("ChatFontNormal") 132 edit_box:SetFontObject("ChatFontNormal")
117 edit_box:SetSize(420, 220) 133 edit_box:SetSize(420, 220)
118 edit_box:HighlightText(0) 134 edit_box:HighlightText(0)
135 edit_box:SetFrameLevel(scroll_frame:GetFrameLevel() - 1)
119 136
120 edit_box:SetScript("OnCursorChanged", _G.ScrollingEdit_OnCursorChanged) 137 edit_box:SetScript("OnCursorChanged", _G.ScrollingEdit_OnCursorChanged)
121 edit_box:SetScript("OnEscapePressed", _G.EditBox_ClearFocus) 138 edit_box:SetScript("OnEscapePressed", _G.EditBox_ClearFocus)
122 edit_box:SetScript("OnShow", function(self) 139 edit_box:SetScript("OnShow", function(self)
123 _G.EditBox_SetFocus(self) 140 _G.EditBox_SetFocus(self)
131 148
132 edit_box:SetScript("OnTextChanged", function(self, user_input) 149 edit_box:SetScript("OnTextChanged", function(self, user_input)
133 local parent = self:GetParent() 150 local parent = self:GetParent()
134 local num_letters = self:GetNumLetters() 151 local num_letters = self:GetNumLetters()
135 _G.ScrollingEdit_OnTextChanged(self, parent) 152 _G.ScrollingEdit_OnTextChanged(self, parent)
136 parent.charCount:SetText(self:GetMaxLetters() - num_letters) 153 parent.charCount:SetFormattedText(_G.BreakUpLargeNumbers(self:GetMaxLetters() - num_letters))
137 154
138 if num_letters > 0 then 155 if num_letters > 0 then
139 panel.submitButton:Enable(); 156 panel.submitButton:Enable();
157 else
158 panel.submitButton:Disable()
140 end 159 end
141 end) 160 end)
142 161
143 edit_box:SetScript("OnUpdate", function(self, elapsed) 162 edit_box:SetScript("OnUpdate", function(self, elapsed)
144 _G.ScrollingEdit_OnUpdate(self, elapsed, self:GetParent()) 163 _G.ScrollingEdit_OnUpdate(self, elapsed, self:GetParent())
145 end) 164 end)
146 165
166 edit_container:SetScript("OnMouseUp", function()
167 _G.EditBox_SetFocus(edit_box)
168 end)
169
170 scroll_frame.edit_box = edit_box
147 scroll_frame:SetScrollChild(edit_box) 171 scroll_frame:SetScrollChild(edit_box)
148 172
149 local char_count = scroll_frame:CreateFontString(nil, "OVERLAY", "GameFontDisableLarge") 173 local char_count = scroll_frame:CreateFontString(nil, "OVERLAY", "GameFontDisableLarge")
150 char_count:SetPoint("BOTTOMRIGHT", -15, 0) 174 char_count:SetPoint("BOTTOMRIGHT", -15, 0)
151 scroll_frame.charCount = char_count 175 scroll_frame.charCount = char_count
169 _G.HideUIPanel(panel) 193 _G.HideUIPanel(panel)
170 end) 194 end)
171 panel.submitButton = submit 195 panel.submitButton = submit
172 end 196 end
173 197
174 local function CreateUnitComment(unit_type, unit_idnum) 198 local function CreateUnitComment(unit_id, unit_type, unit_idnum)
199 comment_frame.subject_name:SetText(_G.UnitName(unit_id))
200 comment_frame.subject_data:SetFormattedText("(%s #%d)", private.UNIT_TYPE_NAMES[unit_type + 1], unit_idnum)
201 comment_frame.scroll_frame.edit_box:SetText("")
175 comment_frame:Show() 202 comment_frame:Show()
176 end 203 end
177 204
178 local function CreateCursorComment() 205 local function CreateCursorComment()
179 -- TODO: Implement! 206 -- TODO: Implement!
200 227
201 if not unit_idnum then 228 if not unit_idnum then
202 WDP:Printf("Unable to determine unit from '%s'", arg) 229 WDP:Printf("Unable to determine unit from '%s'", arg)
203 return 230 return
204 end 231 end
205 CreateUnitComment(unit_type, unit_idnum) 232 CreateUnitComment(arg, unit_type, unit_idnum)
206 end 233 end