Mercurial > wow > squawk
comparison Squawk.lua @ 13:0ca5ec0b7502
We have an ldb tooltip now! Still need to make it pretty.
author | wobin |
---|---|
date | Thu, 23 Apr 2009 17:00:45 +1000 |
parents | 2231fd3f139b |
children | 18c33a32ba31 |
comparison
equal
deleted
inserted
replaced
12:d069c3e6379b | 13:0ca5ec0b7502 |
---|---|
71 -- cleared from Settings.Requested | 71 -- cleared from Settings.Requested |
72 -- 2) Follower is offline | 72 -- 2) Follower is offline |
73 -- - The next time Follower is online and recieves a Squawk we check if there | 73 -- - The next time Follower is online and recieves a Squawk we check if there |
74 -- is a Settings.Requested for that name, and if so assume they have approved | 74 -- is a Settings.Requested for that name, and if so assume they have approved |
75 -- and clear/add records appropriately. | 75 -- and clear/add records appropriately. |
76 -- | |
77 -- For updating, there can be a few methods. | |
78 -- | |
79 -- Guild open: you're not private, you broadcast to the guild your last X | |
80 -- squawks on login | |
81 -- | |
82 -- followers: | |
76 --]] | 83 --]] |
77 Model.Squawk = {} | 84 Model.Squawk = {} |
78 local Squawk = Model.Squawk | 85 local Squawk = Model.Squawk |
79 | 86 local function wrap(str, limit) |
87 limit = limit or 72 | |
88 local here = 1 | |
89 return str:gsub("(%s+)()(%S+)()", | |
90 function(sp, st, word, fi) | |
91 if fi-here > limit then | |
92 here = st | |
93 return "\n"..word | |
94 end | |
95 end) | |
96 end | |
80 function Squawk:new(Message, Owner) | 97 function Squawk:new(Message, Owner) |
81 local o = {} | 98 local o = {} |
82 o.Owner = Owner or UnitName("player") | 99 o.Owner = Owner or UnitName("player") |
83 o.Message = Message | 100 o.Message = wrap(Message) |
84 o.Time = time() | 101 o.Time = time() |
85 local reply, to = strsplit("@", ((strsplit(" ", Message)))) | 102 local reply, to = strsplit("@", ((strsplit(" ", Message)))) |
86 if reply == "" then | 103 if reply == "" then |
87 o.ReplyTo = to | 104 o.ReplyTo = to |
88 end | 105 end |
330 for name,_ in pairs(Settings.Blocked) do | 347 for name,_ in pairs(Settings.Blocked) do |
331 self:Print(name) | 348 self:Print(name) |
332 end | 349 end |
333 end | 350 end |
334 | 351 |
352 local TimeSpan = { [1] = {"second", 60, 1}, | |
353 [2] = {"minute", 3600, 60}, | |
354 [3] = {"hour", 86400, 3600} } | |
355 | |
356 function View:GetTime(stime) | |
357 local lapsed = difftime(time(), stime) | |
358 if lapsed < 86400 then -- if we're still in the same day... | |
359 for _,span in ipairs(TimeSpan) do | |
360 if lapsed < span[2] then | |
361 local timespan = math.floor(lapsed/span[3]) | |
362 if timespan == 1 then | |
363 timespan = timespan .." ".. span[1] | |
364 else | |
365 timespan = timespan .. " ".. span[1].."s" | |
366 end | |
367 return timespan.. " ago" | |
368 end | |
369 end | |
370 end | |
371 return date("%I:%M %p %b %d", stime) | |
372 end | |
373 | |
335 local LDBFeed = LibStub("LibDataBroker-1.1"):NewDataObject("Squawk", {type = "data source", text = "Awk!"}) | 374 local LDBFeed = LibStub("LibDataBroker-1.1"):NewDataObject("Squawk", {type = "data source", text = "Awk!"}) |
336 local QTip = LibStub("LibQTip-1.0") | 375 local QTip = LibStub("LibQTip-1.0") |
337 | 376 |
377 local function AddLine(tooltip, Line, Number, Owner, TimeStamp) | |
378 if #Line < 79 then | |
379 tooltip:AddLine(Number, Owner, Line, TimeStamp) | |
380 else | |
381 tooltip:AddLine(Number, Owner, Line:sub(1, 80).."-", TimeStamp) | |
382 AddLine(tooltip, Line:sub(81)) | |
383 end | |
384 end | |
385 | |
338 function LDBFeed:OnEnter() | 386 function LDBFeed:OnEnter() |
339 local tooltip = QTip:Acquire("Squawk",3, "LEFT", "LEFT", "RIGHT") | 387 local tooltip = QTip:Acquire("Squawk",4, "LEFT", "LEFT", "LEFT", "RIGHT") |
340 self.tooltip = tooltip | 388 self.tooltip = tooltip |
341 tooltip:AddHeader('Name') | 389 tooltip:AddHeader('Squawk') |
342 tooltip:AddLine('testUser', 'Squawk!', '3 min ago') | 390 for i,squawk in ipairs(Model.Squawks) do |
391 if #squawk.Message > 79 then | |
392 local head = true | |
393 local message = {strsplit("\n",squawk.Message)} | |
394 for _,line in ipairs(message) do | |
395 if head then | |
396 AddLine(tooltip, line, i..".", squawk.Owner, View:GetTime(squawk.Time)) | |
397 head = false | |
398 else | |
399 AddLine(tooltip, line) | |
400 end | |
401 end | |
402 else | |
403 tooltip:AddLine(i..".", squawk.Owner, squawk.Message, View:GetTime(squawk.Time)) | |
404 end | |
405 end | |
343 tooltip:SmartAnchorTo(self) | 406 tooltip:SmartAnchorTo(self) |
344 tooltip:Show() | 407 tooltip:Show() |
345 end | 408 end |
346 | 409 |
347 function LDBFeed:OnTooltipShow() | 410 function LDBFeed:OnTooltipShow() |