Mercurial > wow > squawk
comparison View.lua @ 18:a3328fffef5c
Split of main file into components
| author | wobin |
|---|---|
| date | Thu, 07 May 2009 02:52:23 +1000 |
| parents | |
| children | 431f2fce08f2 |
comparison
equal
deleted
inserted
replaced
| 17:2a73deb7bc54 | 18:a3328fffef5c |
|---|---|
| 1 local View = Squawk.View | |
| 2 local Model = Squawk.Model | |
| 3 local Settings = Model.UserSettings | |
| 4 local Controller = Squawk.Controller | |
| 5 local Squawks = Model.Squawks | |
| 6 | |
| 7 -- View -- | |
| 8 | |
| 9 function View:UpdateSquawkList() | |
| 10 self:Print("Updated Squawk List") | |
| 11 self:ShowMeMySquawks() | |
| 12 end | |
| 13 | |
| 14 function View:NotifyOfPending(Name) | |
| 15 self:Print(Name.." will have to approve your request") | |
| 16 end | |
| 17 | |
| 18 function View:NotifyOfPendingRequest(Name) | |
| 19 self:Print(Name.." wants to follow you.") | |
| 20 end | |
| 21 | |
| 22 function View:NotifyOfNewFollowing(Name) | |
| 23 self:Print("You are now following "..Name) | |
| 24 end | |
| 25 | |
| 26 function View:NotifyOfUnfollowing(Name) | |
| 27 self:Print("You are no longer following "..Name) | |
| 28 end | |
| 29 | |
| 30 function View:NotifyOfNewFollower(Name) | |
| 31 self:Print(Name.." is now following you") | |
| 32 end | |
| 33 | |
| 34 function View:ShowMeMySquawks() | |
| 35 for _,squawk in ipairs(Model.Squawks.Main) do | |
| 36 self:Print(squawk.Message) | |
| 37 end | |
| 38 end | |
| 39 | |
| 40 function View:ShowMeMyFollowers() | |
| 41 self:Print("My followers are:") | |
| 42 for name,_ in pairs(Settings.Follower) do | |
| 43 self:Print(name) | |
| 44 end | |
| 45 end | |
| 46 | |
| 47 function View:ShowMeWhoImFollowing() | |
| 48 self:Print("I am following:") | |
| 49 for name,_ in pairs(Settings.Following) do | |
| 50 self:Print(name) | |
| 51 end | |
| 52 end | |
| 53 | |
| 54 function View:ShowMeWhoIveBlocked() | |
| 55 self:Print("I've blocked:") | |
| 56 for name,_ in pairs(Settings.Blocked) do | |
| 57 self:Print(name) | |
| 58 end | |
| 59 end | |
| 60 | |
| 61 local TimeSpan = { [1] = {"second", 60, 1}, | |
| 62 [2] = {"minute", 3600, 60}, | |
| 63 [3] = {"hour", 86400, 3600} } | |
| 64 | |
| 65 function View:GetTime(stime) | |
| 66 local lapsed = difftime(time(), stime) | |
| 67 if lapsed < 86400 then -- if we're still in the same day... | |
| 68 for _,span in ipairs(TimeSpan) do | |
| 69 if lapsed < span[2] then | |
| 70 local timespan = math.floor(lapsed/span[3]) | |
| 71 if timespan == 1 then | |
| 72 timespan = timespan .." ".. span[1] | |
| 73 else | |
| 74 timespan = timespan .. " ".. span[1].."s" | |
| 75 end | |
| 76 return timespan.. " ago" | |
| 77 end | |
| 78 end | |
| 79 end | |
| 80 return date("%I:%M %p %b %d", stime) | |
| 81 end | |
| 82 | |
| 83 local LDBFeed = LibStub("LibDataBroker-1.1"):NewDataObject("Squawk", {type = "data source", text = "Awk!"}) | |
| 84 local QTip = LibStub("LibQTip-1.0") | |
| 85 local QTipClick = LibStub("LibQTipClick-1.0") | |
| 86 local tooltip = {} | |
| 87 | |
| 88 local function HideTooltip() | |
| 89 if MouseIsOver(tooltip) then return end | |
| 90 tooltip:SetScript("OnLeave", nil) | |
| 91 tooltip:Hide() | |
| 92 QTip:Release(tooltip) | |
| 93 tooltip = nil | |
| 94 end | |
| 95 | |
| 96 local function ReplyToMe(cell, Owner, event) | |
| 97 View:Print("Replying to @"..Owner) | |
| 98 end | |
| 99 | |
| 100 local function AddLine(tooltip, Line, Number, Owner, TimeStamp) | |
| 101 local x,y | |
| 102 if #Line < 79 then | |
| 103 y,x = tooltip:AddNormalLine(Number, Owner, Line, TimeStamp) | |
| 104 else | |
| 105 y,x = tooltip:AddNormalLine(Number, Owner, Line:sub(1, 80).."-", TimeStamp) | |
| 106 AddLine(tooltip, Line:sub(81)) | |
| 107 end | |
| 108 if not TimeStamp then return end | |
| 109 | |
| 110 -- Now add the reply clickback | |
| 111 tooltip:SetCell(y, 5, " ", Owner) | |
| 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 | |
| 117 end | |
| 118 | |
| 119 function LDBFeed:OnEnter() | |
| 120 tooltip = QTipClick:Acquire("Squawk",5, "LEFT", "CENTER", "LEFT", "RIGHT", "RIGHT") | |
| 121 tooltip:Clear() | |
| 122 tooltip:SetCallback("OnMouseDown", ReplyToMe) | |
| 123 self.tooltip = tooltip | |
| 124 for i,squawk in ipairs(Squawks:GetLast10()) do | |
| 125 local head = true | |
| 126 local message = {strsplit("\n",squawk.Message)} | |
| 127 for _,line in ipairs(message) do | |
| 128 if head then | |
| 129 AddLine(tooltip, line, i..".", squawk.Owner, View:GetTime(squawk.Time)) | |
| 130 head = false | |
| 131 else | |
| 132 AddLine(tooltip, line) | |
| 133 end | |
| 134 end | |
| 135 end | |
| 136 tooltip:SmartAnchorTo(self) | |
| 137 tooltip:SetScript("OnLeave", HideTooltip) | |
| 138 tooltip:Show() | |
| 139 end | |
| 140 | |
| 141 function LDBFeed:OnLeave() | |
| 142 HideTooltip() | |
| 143 end | |
| 144 --[[ | |
| 145 | |
| 146 function LDBFeed:OnClick(button) | |
| 147 editbox:ClearAllPoints() | |
| 148 editbox:SetPoint(GetTipAnchor(self)) | |
| 149 editbox:Show() | |
| 150 end | |
| 151 | |
| 152 local function GetTipAnchor(frame) | |
| 153 if not x or not y then return "TOPLEFT", frame, "BOTTOMLEFT" end | |
| 154 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" | |
| 156 return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf | |
| 157 end | |
| 158 | |
| 159 local editbox = CreateFrame('EditBox', nil, UIParent) | |
| 160 editbox:Hide() | |
| 161 editbox:SetAutoFocus(true) | |
| 162 editbox:SetHeight(32) | |
| 163 editbox:SetWidth(350) | |
| 164 editbox:SetFrameStrata("HIGH") | |
| 165 editbox:SetFontObject('GameFontHighlightSmall') | |
| 166 lib.editbox = editbox | |
| 167 | |
| 168 editbox:SetScript("OnEscapePressed", editbox.ClearFocus) | |
| 169 editbox:SetScript("OnEnterPressed", editbox.ClearFocus) | |
| 170 editbox:SetScript("OnEditFocusLost", editbox.Hide) | |
| 171 editbox:SetScript("OnEditFocusGained", editbox.HighlightText) | |
| 172 editbox:SetScript("OnTextChanged", function(self) | |
| 173 self:SetText(self:GetParent().val) | |
| 174 self:HighlightText() | |
| 175 end) | |
| 176 | |
| 177 local left = editbox:CreateTexture(nil, "BACKGROUND") | |
| 178 left:SetWidth(8) left:SetHeight(20) | |
| 179 left:SetPoint("LEFT", -5, 0) | |
| 180 left:SetTexture("Interface\\Common\\Common-Input-Border") | |
| 181 left:SetTexCoord(0, 0.0625, 0, 0.625) | |
| 182 | |
| 183 local right = editbox:CreateTexture(nil, "BACKGROUND") | |
| 184 right:SetWidth(8) right:SetHeight(20) | |
| 185 right:SetPoint("RIGHT", 0, 0) | |
| 186 right:SetTexture("Interface\\Common\\Common-Input-Border") | |
| 187 right:SetTexCoord(0.9375, 1, 0, 0.625) | |
| 188 | |
| 189 local center = editbox:CreateTexture(nil, "BACKGROUND") | |
| 190 center:SetHeight(20) | |
| 191 center:SetPoint("RIGHT", right, "LEFT", 0, 0) | |
| 192 center:SetPoint("LEFT", left, "RIGHT", 0, 0) | |
| 193 center:SetTexture("Interface\\Common\\Common-Input-Border") | |
| 194 center:SetTexCoord(0.0625, 0.9375, 0, 0.625) | |
| 195 | |
| 196 function lib.OpenEditbox(self) | |
| 197 editbox:SetText(self.val) | |
| 198 editbox:SetParent(self) | |
| 199 editbox:SetPoint("LEFT", self) | |
| 200 editbox:SetPoint("RIGHT", self) | |
| 201 editbox:Show() | |
| 202 end | |
| 203 --]] | |
| 204 |
