Mercurial > wow > wowdb-profiler
comparison Comments.lua @ 249:3fe3e55c327e
Added command and GUI for prototype of an in-game comment-submission system.
author | James D. Callahan III <jcallahan@curse.com> |
---|---|
date | Thu, 14 Mar 2013 16:36:36 -0500 |
parents | |
children | 88d2c426f876 |
comparison
equal
deleted
inserted
replaced
248:4cb26edfd905 | 249:3fe3e55c327e |
---|---|
1 -- LUA API ------------------------------------------------------------ | |
2 | |
3 local _G = getfenv(0) | |
4 | |
5 local table = _G.table | |
6 | |
7 -- ADDON NAMESPACE ---------------------------------------------------- | |
8 | |
9 local ADDON_NAME, private = ... | |
10 | |
11 local LibStub = _G.LibStub | |
12 local WDP = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME) | |
13 | |
14 local ParseGUID = private.ParseGUID | |
15 | |
16 -- HELPERS ------------------------------------------------------------ | |
17 | |
18 local comment_frame | |
19 do | |
20 local panel = _G.CreateFrame("Frame", "WDP_CommentFrame", _G.UIParent, "TranslucentFrameTemplate") | |
21 panel:SetSize(480, 454) | |
22 panel:SetPoint("CENTER", _G.UIParent, "CENTER") | |
23 panel:SetFrameStrata("DIALOG") | |
24 panel.Bg:SetTexture([[Interface\FrameGeneral\UI-Background-Rock]], true, true) | |
25 panel.Bg:SetHorizTile(true) | |
26 panel.Bg:SetVertTile(true) | |
27 panel:Hide() | |
28 comment_frame = panel | |
29 | |
30 table.insert(_G.UISpecialFrames, panel:GetName()) | |
31 | |
32 local streaks = panel:CreateTexture("$parentTopTileStreaks", "BORDER", "_UI-Frame-TopTileStreaks", -6) | |
33 streaks:SetPoint("TOPLEFT", 13, -13) | |
34 streaks:SetPoint("BOTTOMRIGHT", panel, "TOPRIGHT", -13, -35) | |
35 | |
36 local header = _G.CreateFrame("Frame", "$parentHeader", panel, "TranslucentFrameTemplate") | |
37 -- header:SetSize(180, 45) | |
38 header:SetSize(128, 64) | |
39 header:SetPoint("CENTER", panel, "TOP", 0, -8) | |
40 header.Bg:SetTexture([[Interface\FrameGeneral\UI-Background-Marble]]) | |
41 header.Bg:SetHorizTile(true) | |
42 header.Bg:SetVertTile(true) | |
43 panel.header = header | |
44 | |
45 local logo = header:CreateTexture(nil, "ARTWORK") | |
46 logo:SetTexture([[Interface\AddOns\WoWDBProfiler\wowdb-logo]]) | |
47 logo:SetPoint("TOPLEFT", header, 10, -10) | |
48 logo:SetPoint("BOTTOMRIGHT", header, -10, 10) | |
49 | |
50 --[[ | |
51 local header_label = header:CreateFontString(nil, "ARTWORK", "GameFontNormal") | |
52 header_label:SetPoint("CENTER", 0, 0) | |
53 header_label:SetText(ADDON_NAME) | |
54 ]] | |
55 | |
56 local close = _G.CreateFrame("Button", nil, panel, "UIPanelCloseButton") | |
57 close:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -7, -7) | |
58 | |
59 local scroll_frame = _G.CreateFrame("ScrollFrame", "$parentScrollFrame", panel) | |
60 scroll_frame:SetSize(435, 150) | |
61 scroll_frame:SetPoint("BOTTOM", 0, 70) | |
62 | |
63 scroll_frame:SetScript("OnScrollRangeChanged", function(self, x, y) | |
64 _G.ScrollFrame_OnScrollRangeChanged(self, x, y) | |
65 end) | |
66 | |
67 scroll_frame:SetScript("OnVerticalScroll", function(self, offset) | |
68 local scrollbar = self.ScrollBar | |
69 scrollbar:SetValue(offset) | |
70 | |
71 local min, max = scrollbar:GetMinMaxValues() | |
72 | |
73 if offset == 0 then | |
74 scrollbar.ScrollUpButton:Disable() | |
75 else | |
76 scrollbar.ScrollUpButton:Enable() | |
77 end | |
78 | |
79 if (scrollbar:GetValue() - max) == 0 then | |
80 scrollbar.ScrollDownButton:Disable() | |
81 else | |
82 scrollbar.ScrollDownButton:Enable() | |
83 end | |
84 end) | |
85 | |
86 scroll_frame:SetScript("OnMouseWheel", function(self, delta) | |
87 _G.ScrollFrameTemplate_OnMouseWheel(self, delta) | |
88 end) | |
89 | |
90 local edit_container = _G.CreateFrame("Frame", nil, scroll_frame) | |
91 edit_container:SetPoint("TOPLEFT", scroll_frame, -7, 7) | |
92 edit_container:SetPoint("BOTTOMRIGHT", scroll_frame, 7, -7) | |
93 edit_container:SetFrameLevel(scroll_frame:GetFrameLevel() - 1) | |
94 edit_container:SetBackdrop({ | |
95 bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], | |
96 edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], | |
97 tile = true, | |
98 tileSize = 16, | |
99 edgeSize = 16, | |
100 insets = { | |
101 left = 5, | |
102 right = 5, | |
103 top = 5, | |
104 bottom = 5 | |
105 } | |
106 }) | |
107 | |
108 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) | |
110 | |
111 local edit_box = _G.CreateFrame("EditBox", nil, scroll_frame) | |
112 edit_box:SetMultiLine(true) | |
113 edit_box:SetMaxLetters(3000) | |
114 edit_box:EnableMouse(true) | |
115 edit_box:SetAutoFocus(false) | |
116 edit_box:SetFontObject("ChatFontNormal") | |
117 edit_box:SetSize(420, 220) | |
118 edit_box:HighlightText(0) | |
119 | |
120 edit_box:SetScript("OnCursorChanged", _G.ScrollingEdit_OnCursorChanged) | |
121 edit_box:SetScript("OnEscapePressed", _G.EditBox_ClearFocus) | |
122 edit_box:SetScript("OnShow", function(self) | |
123 _G.EditBox_SetFocus(self) | |
124 | |
125 if self:GetNumLetters() > 0 then | |
126 panel.submitButton:Enable() | |
127 else | |
128 panel.submitButton:Disable() | |
129 end | |
130 end) | |
131 | |
132 edit_box:SetScript("OnTextChanged", function(self, user_input) | |
133 local parent = self:GetParent() | |
134 local num_letters = self:GetNumLetters() | |
135 _G.ScrollingEdit_OnTextChanged(self, parent) | |
136 parent.charCount:SetText(self:GetMaxLetters() - num_letters) | |
137 | |
138 if num_letters > 0 then | |
139 panel.submitButton:Enable(); | |
140 end | |
141 end) | |
142 | |
143 edit_box:SetScript("OnUpdate", function(self, elapsed) | |
144 _G.ScrollingEdit_OnUpdate(self, elapsed, self:GetParent()) | |
145 end) | |
146 | |
147 scroll_frame:SetScrollChild(edit_box) | |
148 | |
149 local char_count = scroll_frame:CreateFontString(nil, "OVERLAY", "GameFontDisableLarge") | |
150 char_count:SetPoint("BOTTOMRIGHT", -15, 0) | |
151 scroll_frame.charCount = char_count | |
152 | |
153 local scroll_bar = _G.CreateFrame("Slider", "$parentScrollBar", scroll_frame, "UIPanelScrollBarTemplate") | |
154 scroll_bar:SetPoint("TOPLEFT", scroll_frame, "TOPRIGHT", -13, -16) | |
155 scroll_bar:SetPoint("BOTTOMLEFT", scroll_frame, "BOTTOMRIGHT", -13, 16) | |
156 scroll_frame.ScrollBar = scroll_bar | |
157 | |
158 _G.ScrollFrame_OnLoad(scroll_frame) | |
159 | |
160 local submit = _G.CreateFrame("Button", "$parentSubmit", panel, "GameMenuButtonTemplate") | |
161 submit:SetSize(160, 30) | |
162 submit:SetPoint("BOTTOM", 0, 15) | |
163 submit:SetText(_G.SUBMIT) | |
164 submit:Enable(false) | |
165 | |
166 submit:SetScript("OnClick", function() | |
167 -- TODO: Make this assign the comment to the correct SavedVariables entry. | |
168 edit_box:SetText("") | |
169 _G.HideUIPanel(panel) | |
170 end) | |
171 panel.submitButton = submit | |
172 end | |
173 | |
174 local function CreateUnitComment(unit_type, unit_idnum) | |
175 comment_frame:Show() | |
176 end | |
177 | |
178 local function CreateCursorComment() | |
179 -- TODO: Implement! | |
180 end | |
181 | |
182 -- METHODS ------------------------------------------------------------ | |
183 | |
184 function private.ProcessCommentCommand(arg) | |
185 if not arg or arg == "" then | |
186 WDP:Print("You must supply a valid comment type.") | |
187 return | |
188 end | |
189 | |
190 if arg == "cursor" then | |
191 WDP:Print("Not yet implemented.") | |
192 return | |
193 end | |
194 | |
195 if not _G.UnitExists(arg) then | |
196 WDP:Printf("Unit '%s' does not exist.", arg) | |
197 return | |
198 end | |
199 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID(arg)) | |
200 | |
201 if not unit_idnum then | |
202 WDP:Printf("Unable to determine unit from '%s'", arg) | |
203 return | |
204 end | |
205 CreateUnitComment(unit_type, unit_idnum) | |
206 end |