Mercurial > wow > squawk
changeset 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 | 22178ac75587 |
files | Controller.lua Model.lua Squawk.lua View.lua arrow.tga |
diffstat | 5 files changed, 102 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/Controller.lua Thu May 07 02:52:23 2009 +1000 +++ b/Controller.lua Tue May 12 00:57:59 2009 +1000 @@ -10,11 +10,11 @@ if Settings:IsPrivate() then Settings:AddPending(Name) self:PutForwardFollowRequest(Name) - self:SendMessageToTarget(Name, "#Pending|"..UnitName("player")) + self:SendMessageToTarget(Name, "#Pending|"..self.Name) else Settings:AddFollower(Name) View:NotifyOfNewFollower(Name) - self:SendMessageToTarget(Name, "#Follow|"..UnitName("player")) + self:SendMessageToTarget(Name, "#Follow|"..self.Name) end end @@ -23,13 +23,13 @@ end function Controller:IWantToFollowThem(Name) - self:SendMessageToTarget(Name, "#Request|"..UnitName("player")) + self:SendMessageToTarget(Name, "#Request|"..self.Name) Settings:AddRequested(Name) end function Controller:IWantToUnfollowThem(Name) Settings:RemoveFollowing(Name) - self:SendMessageToTarget(Name, "#Unfollow|"..UnitName("player")) + self:SendMessageToTarget(Name, "#Unfollow|"..self.Name) View:NotifyOfUnfollowing(Name) end @@ -38,7 +38,7 @@ View:NotifyOfNewFollowing(Name) end -function Controller:AddANewSquawk(Name, Message, Source) +function Controller:AddANewSquawk(Name, Class, Message, Reply, Source) if not Settings.Blocked[Name] then if Source == "WHISPER" then @@ -47,17 +47,17 @@ end if not Settings.Following[Name] then -- If we're no longer following this person - self:SendMessageToTarget(Name, "#Unfollow|"..UnitName("player")) + self:SendMessageToTarget(Name, "#Unfollow|"..self.Name) return end end - if Source == "GUILD" and Name == UnitName("player") then + if Source == "GUILD" and Name == self.Name then return end - table.insert(Model.Squawks, Squawks:new(Message, Name)) - View:UpdateSquawkList() + table.insert(Model.Squawks, Squawks:new(Message, Name, Class, Reply)) + --View:UpdateSquawkList() end end @@ -75,14 +75,14 @@ end end -function Controller:SendNewSquawk(Message) +function Controller:SendNewSquawk(Message, ReplyStamp) if not Settings:IsPrivate() then - self:SendMessageToGuild("#Squawk|"..UnitName("player").."|"..Message) + self:SendMessageToGuild("#Squawk|"..self.Name.."|"..self.Class.."|"..ReplyStamp or "".."|"..Message) end - self:AddANewSquawk(UnitName("player"), Message) + self:AddANewSquawk(self.Name, self.Class, Message, ReplyStamp) for name, _ in pairs(Settings.Following) do - self:SendMessageToTarget(name, "#Squawk|"..UnitName("player").."|"..Message) + self:SendMessageToTarget(name, "#Squawk|"..self.Name.."|"..self.Class.."|"..ReplyStamp or "".."|"..Message) end end @@ -97,7 +97,7 @@ function Controller:ApprovePendingRequest(Name) Settings:AddFollower(Name) View:NotifyOfNewFollower(Name) - self:SendMessageToTarget(Name, "#Follow|"..UnitName("player")) + self:SendMessageToTarget(Name, "#Follow|"..self.Name) end @@ -120,8 +120,7 @@ } function Controller:ReceiveMessage(Message, Distribution, Sender) - local command, name, info = strsplit("|",Message) - View:Print(Distribution..":"..Message) - Parse[command](Controller, name, info, Distribution) + local command, name, class, reply, info = strsplit("|",Message) + Parse[command](Controller, name, class, reply, info, Distribution) end
--- a/Model.lua Thu May 07 02:52:23 2009 +1000 +++ b/Model.lua Tue May 12 00:57:59 2009 +1000 @@ -48,10 +48,24 @@ Squawks.Main = {} Squawks.Owners = {} + +local classcolours = { +["DEATHKNIGHT"] = "C41F3B", +["DRUID"] = "FF7D0A", +["HUNTER"] = "ABD473", +["MAGE"] = "69CCF0", +["PALADIN"] = "F58CBA", +["PRIEST"] = "FFFFFF", +["ROGUE"] = "FFF569", +["SHAMAN"] = "2459FF", +["WARLOCK"] = "9482C9", +["WARRIOR"] = "C79C6E", +} + local function wrap(str, limit) limit = limit or 72 - local here = 1 - return str:gsub("(%s+)()(%S+)()", + local here = 1 + return str:gsub("|c%x-|H.-|h(.-)|h|r", "%1"):gsub("(%s+)()(%S+)()", function(sp, st, word, fi) if fi-here > limit then here = st @@ -60,19 +74,21 @@ end) end -function Squawks:new(Message, Owner) +function Squawks:new(Message, Owner, Class, ReplyStamp) + View:Print("New: "..ReplyStamp) local o = {} o.Owner = Owner or UnitName("player") o.Message = wrap(Message) o.Time = time() local reply, to = strsplit("@", ((strsplit(" ", Message)))) if reply == "" then - o.ReplyTo = to + o.ReplyTo = to:match("%P+") -- Get everything except punctuation + o.ReplyStamp = ReplyStamp end o.Related = {} - for word in string.gmatch(Message, "@(%a+)") do + for word in string.gmatch(Message, "@(%S+)") do if word ~= o.ReplyTo or "" then table.insert(o.Related, word) end @@ -84,13 +100,22 @@ table.insert(self.Main, o) + if not self.Squawkers[Owner] then + self.Squawkers[Owner] = {name = Owner, class=Class} + end + if not self.Owners[Owner] then self.Owners[Owner] = {} end + table.insert(self.Owners[Owner], o) return o end +function Squawks:OwnerString(squawk) + return "|cff"..classcolours[self.Squawkers[squawk.Owner].class or "WARRIOR"]..squawk.Owner.."|r" +end + function Squawks:Reload() for _,squawk in ipairs(Model.Squawks.Main) do if not self.Owners[squawk.Owner] then
--- a/Squawk.lua Thu May 07 02:52:23 2009 +1000 +++ b/Squawk.lua Tue May 12 00:57:59 2009 +1000 @@ -18,6 +18,7 @@ local defaults = { profile = { Squawks = {}, + Squawkers = {}, Follower = {}, Following = {}, Pending = {}, @@ -30,6 +31,7 @@ function Squawk:OnInitialize() Model.db = LibStub("AceDB-3.0"):New("SquawkDB", defaults) Model.Squawks.Main = Model.db.profile.Squawks + Model.Squawks.Squawkers = Model.db.profile.Squawkers Settings.Follower = Model.db.profile.Follower Settings.Following = Model.db.profile.Following Settings.Pending = Model.db.profile.Pending @@ -43,5 +45,8 @@ LibStub("AceConsole-3.0"):Embed(View) setmetatable(View, SquawkViewMeta) + Controller.Name = UnitName("player") + _, Controller.Class = UnitClass("player") + Model.Squawks.Reload(Model.Squawks) -- Retrain the table lookups end
--- a/View.lua Thu May 07 02:52:23 2009 +1000 +++ b/View.lua Tue May 12 00:57:59 2009 +1000 @@ -65,9 +65,12 @@ function View:GetTime(stime) local lapsed = difftime(time(), stime) if lapsed < 86400 then -- if we're still in the same day... - for _,span in ipairs(TimeSpan) do + for inc,span in ipairs(TimeSpan) do if lapsed < span[2] then local timespan = math.floor(lapsed/span[3]) + if inc == 3 then + timespan = tonumber(string.format("%.1f", lapsed/span[3])) + end if timespan == 1 then timespan = timespan .." ".. span[1] else @@ -84,9 +87,11 @@ local QTip = LibStub("LibQTip-1.0") local QTipClick = LibStub("LibQTipClick-1.0") local tooltip = {} +local editbox = CreateFrame('EditBox', nil, UIParent) local function HideTooltip() - if MouseIsOver(tooltip) then return end + if not tooltip then return end + if MouseIsOver(tooltip) or MouseIsOver(editbox) then return end tooltip:SetScript("OnLeave", nil) tooltip:Hide() QTip:Release(tooltip) @@ -94,30 +99,28 @@ end local function ReplyToMe(cell, Owner, event) - View:Print("Replying to @"..Owner) + editbox.Timestamp = Owner[2] + LDBFeed.OnClick(LDBFeed, "LeftButton", "@"..Owner[1]:gsub("|c%x%x%x%x%x%x%x%x(.-)|r", "%1")) end local function AddLine(tooltip, Line, Number, Owner, TimeStamp) local x,y if #Line < 79 then - y,x = tooltip:AddNormalLine(Number, Owner, Line, TimeStamp) + y,x = tooltip:AddNormalLine(Number, Owner, Line, View:GetTime(TimeStamp)) else - y,x = tooltip:AddNormalLine(Number, Owner, Line:sub(1, 80).."-", TimeStamp) + y,x = tooltip:AddNormalLine(Number, Owner, Line:sub(1, 80).."-", View:GetTime(TimeStamp)) AddLine(tooltip, Line:sub(81)) end if not TimeStamp then return end -- Now add the reply clickback - tooltip:SetCell(y, 5, " ", Owner) - tooltip.lines[y].cells[5]:SetBackdrop({bgFile= "Interface\\Addons\\Squawk\\reply"}) - if not tooltip.lines[y].cells[5]:GetScript("OnHide") then - tooltip.lines[y].cells[5]:SetScript("OnHide", function(self) self:SetBackdrop(nil) self:SetScript("OnHide", nil) end) - end + tooltip:SetCell(y, 5, "|TInterface\\Addons\\Squawk\\reply:0|t", {Owner, TimeStamp}) -- Reply clickback finished end function LDBFeed:OnEnter() tooltip = QTipClick:Acquire("Squawk",5, "LEFT", "CENTER", "LEFT", "RIGHT", "RIGHT") + tooltip.type = "Squawk" tooltip:Clear() tooltip:SetCallback("OnMouseDown", ReplyToMe) self.tooltip = tooltip @@ -126,7 +129,7 @@ local message = {strsplit("\n",squawk.Message)} for _,line in ipairs(message) do if head then - AddLine(tooltip, line, i..".", squawk.Owner, View:GetTime(squawk.Time)) + AddLine(tooltip, line, i..".", Squawks:OwnerString(squawk), squawk.Time) head = false else AddLine(tooltip, line) @@ -141,37 +144,60 @@ function LDBFeed:OnLeave() HideTooltip() end ---[[ -function LDBFeed:OnClick(button) - editbox:ClearAllPoints() - editbox:SetPoint(GetTipAnchor(self)) - editbox:Show() -end + local function GetTipAnchor(frame) - if not x or not y then return "TOPLEFT", frame, "BOTTOMLEFT" end + local x,y = frame:GetCenter() local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or "" local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM" return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf end -local editbox = CreateFrame('EditBox', nil, UIParent) +function LDBFeed:OnClick(button, reply) + editbox:ClearAllPoints() + local frame -- begin terrible hack to place the editbox somewhere close to the tooltip/ldb + if GetMouseFocus():GetParent().type == "Squawk" then -- if we're a tooltip as designated above + frame = GetMouseFocus():GetParent() -- parent to the tooltip + else + frame = GetMouseFocus() -- else parent to the ldb feeder + end + editbox:SetPoint(GetTipAnchor(frame)) + editbox:Show() + editbox:SetText("") + if reply then + editbox:SetText(reply) + end + HideTooltip(true) +end + + editbox:Hide() editbox:SetAutoFocus(true) editbox:SetHeight(32) editbox:SetWidth(350) +editbox:SetMaxLetters(140) editbox:SetFrameStrata("HIGH") editbox:SetFontObject('GameFontHighlightSmall') -lib.editbox = editbox +LDBFeed.editbox = editbox -editbox:SetScript("OnEscapePressed", editbox.ClearFocus) -editbox:SetScript("OnEnterPressed", editbox.ClearFocus) +editbox:SetScript("OnEscapePressed", function() + editbox:SetText("") + editbox.Timestamp = nil + editbox:ClearFocus() + end) +editbox:SetScript("OnEnterPressed", function() + if #editbox:GetText() > 0 then + View:Print(editbox.Timestamp) + Controller:SendNewSquawk(editbox:GetText(), editbox.Timestamp) + end + editbox.Timestamp = nil + editbox:SetText("") + editbox:ClearFocus() + end) editbox:SetScript("OnEditFocusLost", editbox.Hide) editbox:SetScript("OnEditFocusGained", editbox.HighlightText) editbox:SetScript("OnTextChanged", function(self) - self:SetText(self:GetParent().val) - self:HighlightText() end) local left = editbox:CreateTexture(nil, "BACKGROUND") @@ -193,12 +219,11 @@ center:SetTexture("Interface\\Common\\Common-Input-Border") center:SetTexCoord(0.0625, 0.9375, 0, 0.625) -function lib.OpenEditbox(self) +function LDBFeed.OpenEditbox(self) editbox:SetText(self.val) editbox:SetParent(self) editbox:SetPoint("LEFT", self) editbox:SetPoint("RIGHT", self) editbox:Show() end ---]]