Mercurial > wow > squawk
comparison View.lua @ 19:431f2fce08f2
Added in link stripping
Coloured class names
Reply to specific squawk
Related squawks fixed
new arrow to indicate reply
limit to 140 characters
author | wobin |
---|---|
date | Tue, 12 May 2009 00:57:59 +1000 |
parents | a3328fffef5c |
children |
comparison
equal
deleted
inserted
replaced
18:a3328fffef5c | 19:431f2fce08f2 |
---|---|
63 [3] = {"hour", 86400, 3600} } | 63 [3] = {"hour", 86400, 3600} } |
64 | 64 |
65 function View:GetTime(stime) | 65 function View:GetTime(stime) |
66 local lapsed = difftime(time(), stime) | 66 local lapsed = difftime(time(), stime) |
67 if lapsed < 86400 then -- if we're still in the same day... | 67 if lapsed < 86400 then -- if we're still in the same day... |
68 for _,span in ipairs(TimeSpan) do | 68 for inc,span in ipairs(TimeSpan) do |
69 if lapsed < span[2] then | 69 if lapsed < span[2] then |
70 local timespan = math.floor(lapsed/span[3]) | 70 local timespan = math.floor(lapsed/span[3]) |
71 if inc == 3 then | |
72 timespan = tonumber(string.format("%.1f", lapsed/span[3])) | |
73 end | |
71 if timespan == 1 then | 74 if timespan == 1 then |
72 timespan = timespan .." ".. span[1] | 75 timespan = timespan .." ".. span[1] |
73 else | 76 else |
74 timespan = timespan .. " ".. span[1].."s" | 77 timespan = timespan .. " ".. span[1].."s" |
75 end | 78 end |
82 | 85 |
83 local LDBFeed = LibStub("LibDataBroker-1.1"):NewDataObject("Squawk", {type = "data source", text = "Awk!"}) | 86 local LDBFeed = LibStub("LibDataBroker-1.1"):NewDataObject("Squawk", {type = "data source", text = "Awk!"}) |
84 local QTip = LibStub("LibQTip-1.0") | 87 local QTip = LibStub("LibQTip-1.0") |
85 local QTipClick = LibStub("LibQTipClick-1.0") | 88 local QTipClick = LibStub("LibQTipClick-1.0") |
86 local tooltip = {} | 89 local tooltip = {} |
90 local editbox = CreateFrame('EditBox', nil, UIParent) | |
87 | 91 |
88 local function HideTooltip() | 92 local function HideTooltip() |
89 if MouseIsOver(tooltip) then return end | 93 if not tooltip then return end |
94 if MouseIsOver(tooltip) or MouseIsOver(editbox) then return end | |
90 tooltip:SetScript("OnLeave", nil) | 95 tooltip:SetScript("OnLeave", nil) |
91 tooltip:Hide() | 96 tooltip:Hide() |
92 QTip:Release(tooltip) | 97 QTip:Release(tooltip) |
93 tooltip = nil | 98 tooltip = nil |
94 end | 99 end |
95 | 100 |
96 local function ReplyToMe(cell, Owner, event) | 101 local function ReplyToMe(cell, Owner, event) |
97 View:Print("Replying to @"..Owner) | 102 editbox.Timestamp = Owner[2] |
103 LDBFeed.OnClick(LDBFeed, "LeftButton", "@"..Owner[1]:gsub("|c%x%x%x%x%x%x%x%x(.-)|r", "%1")) | |
98 end | 104 end |
99 | 105 |
100 local function AddLine(tooltip, Line, Number, Owner, TimeStamp) | 106 local function AddLine(tooltip, Line, Number, Owner, TimeStamp) |
101 local x,y | 107 local x,y |
102 if #Line < 79 then | 108 if #Line < 79 then |
103 y,x = tooltip:AddNormalLine(Number, Owner, Line, TimeStamp) | 109 y,x = tooltip:AddNormalLine(Number, Owner, Line, View:GetTime(TimeStamp)) |
104 else | 110 else |
105 y,x = tooltip:AddNormalLine(Number, Owner, Line:sub(1, 80).."-", TimeStamp) | 111 y,x = tooltip:AddNormalLine(Number, Owner, Line:sub(1, 80).."-", View:GetTime(TimeStamp)) |
106 AddLine(tooltip, Line:sub(81)) | 112 AddLine(tooltip, Line:sub(81)) |
107 end | 113 end |
108 if not TimeStamp then return end | 114 if not TimeStamp then return end |
109 | 115 |
110 -- Now add the reply clickback | 116 -- Now add the reply clickback |
111 tooltip:SetCell(y, 5, " ", Owner) | 117 tooltip:SetCell(y, 5, "|TInterface\\Addons\\Squawk\\reply:0|t", {Owner, TimeStamp}) |
112 tooltip.lines[y].cells[5]:SetBackdrop({bgFile= "Interface\\Addons\\Squawk\\reply"}) | |
113 if not tooltip.lines[y].cells[5]:GetScript("OnHide") then | |
114 tooltip.lines[y].cells[5]:SetScript("OnHide", function(self) self:SetBackdrop(nil) self:SetScript("OnHide", nil) end) | |
115 end | |
116 -- Reply clickback finished | 118 -- Reply clickback finished |
117 end | 119 end |
118 | 120 |
119 function LDBFeed:OnEnter() | 121 function LDBFeed:OnEnter() |
120 tooltip = QTipClick:Acquire("Squawk",5, "LEFT", "CENTER", "LEFT", "RIGHT", "RIGHT") | 122 tooltip = QTipClick:Acquire("Squawk",5, "LEFT", "CENTER", "LEFT", "RIGHT", "RIGHT") |
123 tooltip.type = "Squawk" | |
121 tooltip:Clear() | 124 tooltip:Clear() |
122 tooltip:SetCallback("OnMouseDown", ReplyToMe) | 125 tooltip:SetCallback("OnMouseDown", ReplyToMe) |
123 self.tooltip = tooltip | 126 self.tooltip = tooltip |
124 for i,squawk in ipairs(Squawks:GetLast10()) do | 127 for i,squawk in ipairs(Squawks:GetLast10()) do |
125 local head = true | 128 local head = true |
126 local message = {strsplit("\n",squawk.Message)} | 129 local message = {strsplit("\n",squawk.Message)} |
127 for _,line in ipairs(message) do | 130 for _,line in ipairs(message) do |
128 if head then | 131 if head then |
129 AddLine(tooltip, line, i..".", squawk.Owner, View:GetTime(squawk.Time)) | 132 AddLine(tooltip, line, i..".", Squawks:OwnerString(squawk), squawk.Time) |
130 head = false | 133 head = false |
131 else | 134 else |
132 AddLine(tooltip, line) | 135 AddLine(tooltip, line) |
133 end | 136 end |
134 end | 137 end |
139 end | 142 end |
140 | 143 |
141 function LDBFeed:OnLeave() | 144 function LDBFeed:OnLeave() |
142 HideTooltip() | 145 HideTooltip() |
143 end | 146 end |
144 --[[ | 147 |
145 | 148 |
146 function LDBFeed:OnClick(button) | |
147 editbox:ClearAllPoints() | |
148 editbox:SetPoint(GetTipAnchor(self)) | |
149 editbox:Show() | |
150 end | |
151 | 149 |
152 local function GetTipAnchor(frame) | 150 local function GetTipAnchor(frame) |
153 if not x or not y then return "TOPLEFT", frame, "BOTTOMLEFT" end | 151 local x,y = frame:GetCenter() |
154 local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or "" | 152 local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or "" |
155 local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM" | 153 local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM" |
156 return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf | 154 return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf |
157 end | 155 end |
158 | 156 |
159 local editbox = CreateFrame('EditBox', nil, UIParent) | 157 function LDBFeed:OnClick(button, reply) |
158 editbox:ClearAllPoints() | |
159 local frame -- begin terrible hack to place the editbox somewhere close to the tooltip/ldb | |
160 if GetMouseFocus():GetParent().type == "Squawk" then -- if we're a tooltip as designated above | |
161 frame = GetMouseFocus():GetParent() -- parent to the tooltip | |
162 else | |
163 frame = GetMouseFocus() -- else parent to the ldb feeder | |
164 end | |
165 editbox:SetPoint(GetTipAnchor(frame)) | |
166 editbox:Show() | |
167 editbox:SetText("") | |
168 if reply then | |
169 editbox:SetText(reply) | |
170 end | |
171 HideTooltip(true) | |
172 end | |
173 | |
174 | |
160 editbox:Hide() | 175 editbox:Hide() |
161 editbox:SetAutoFocus(true) | 176 editbox:SetAutoFocus(true) |
162 editbox:SetHeight(32) | 177 editbox:SetHeight(32) |
163 editbox:SetWidth(350) | 178 editbox:SetWidth(350) |
179 editbox:SetMaxLetters(140) | |
164 editbox:SetFrameStrata("HIGH") | 180 editbox:SetFrameStrata("HIGH") |
165 editbox:SetFontObject('GameFontHighlightSmall') | 181 editbox:SetFontObject('GameFontHighlightSmall') |
166 lib.editbox = editbox | 182 LDBFeed.editbox = editbox |
167 | 183 |
168 editbox:SetScript("OnEscapePressed", editbox.ClearFocus) | 184 editbox:SetScript("OnEscapePressed", function() |
169 editbox:SetScript("OnEnterPressed", editbox.ClearFocus) | 185 editbox:SetText("") |
186 editbox.Timestamp = nil | |
187 editbox:ClearFocus() | |
188 end) | |
189 editbox:SetScript("OnEnterPressed", function() | |
190 if #editbox:GetText() > 0 then | |
191 View:Print(editbox.Timestamp) | |
192 Controller:SendNewSquawk(editbox:GetText(), editbox.Timestamp) | |
193 end | |
194 editbox.Timestamp = nil | |
195 editbox:SetText("") | |
196 editbox:ClearFocus() | |
197 end) | |
170 editbox:SetScript("OnEditFocusLost", editbox.Hide) | 198 editbox:SetScript("OnEditFocusLost", editbox.Hide) |
171 editbox:SetScript("OnEditFocusGained", editbox.HighlightText) | 199 editbox:SetScript("OnEditFocusGained", editbox.HighlightText) |
172 editbox:SetScript("OnTextChanged", function(self) | 200 editbox:SetScript("OnTextChanged", function(self) |
173 self:SetText(self:GetParent().val) | |
174 self:HighlightText() | |
175 end) | 201 end) |
176 | 202 |
177 local left = editbox:CreateTexture(nil, "BACKGROUND") | 203 local left = editbox:CreateTexture(nil, "BACKGROUND") |
178 left:SetWidth(8) left:SetHeight(20) | 204 left:SetWidth(8) left:SetHeight(20) |
179 left:SetPoint("LEFT", -5, 0) | 205 left:SetPoint("LEFT", -5, 0) |
191 center:SetPoint("RIGHT", right, "LEFT", 0, 0) | 217 center:SetPoint("RIGHT", right, "LEFT", 0, 0) |
192 center:SetPoint("LEFT", left, "RIGHT", 0, 0) | 218 center:SetPoint("LEFT", left, "RIGHT", 0, 0) |
193 center:SetTexture("Interface\\Common\\Common-Input-Border") | 219 center:SetTexture("Interface\\Common\\Common-Input-Border") |
194 center:SetTexCoord(0.0625, 0.9375, 0, 0.625) | 220 center:SetTexCoord(0.0625, 0.9375, 0, 0.625) |
195 | 221 |
196 function lib.OpenEditbox(self) | 222 function LDBFeed.OpenEditbox(self) |
197 editbox:SetText(self.val) | 223 editbox:SetText(self.val) |
198 editbox:SetParent(self) | 224 editbox:SetParent(self) |
199 editbox:SetPoint("LEFT", self) | 225 editbox:SetPoint("LEFT", self) |
200 editbox:SetPoint("RIGHT", self) | 226 editbox:SetPoint("RIGHT", self) |
201 editbox:Show() | 227 editbox:Show() |
202 end | 228 end |
203 --]] | 229 |
204 |