annotate Squawk.lua @ 17:2a73deb7bc54

For Mikma.
author wobin
date Sun, 03 May 2009 00:00:24 +1000
parents 6c28e55a00cf
children a3328fffef5c
rev   line source
wobin@17 1 -- A Twitter client of sorts for World of Warcraft
wobin@17 2 -- Author: Wobin
wobin@17 3 -- Email: wobster@gmail.com
wobin@17 4 --
wobin@17 5 Squawk = LibStub("AceAddon-3.0"):NewAddon("Squawk")
wobin@17 6
wobin@17 7 Squawk.Model = {}
wobin@17 8 Squawk.View = {}
wobin@17 9 Squawk.Controller = {}
wobin@17 10
wobin@17 11 local Model = Squawk.Model
wobin@17 12 local View = Squawk.View
wobin@17 13 local Controller = Squawk.Controller
wobin@17 14
wobin@17 15 Model.UserSettings = {}
wobin@17 16 local Settings = Model.UserSettings
wobin@17 17
wobin@17 18 local defaults = {
wobin@17 19 profile = {
wobin@17 20 Squawks = {},
wobin@17 21 Follower = {},
wobin@17 22 Following = {},
wobin@17 23 Pending = {},
wobin@17 24 Requested = {},
wobin@17 25 Blocked = {},
wobin@17 26 }
wobin@17 27 }
wobin@17 28
wobin@17 29 function Squawk:OnInitialize()
wobin@17 30 Model.db = LibStub("AceDB-3.0"):New("SquawkDB", defaults)
wobin@17 31 Model.Squawks = Model.db.profile.Squawks
wobin@17 32 Settings.Follower = Model.db.profile.Follower
wobin@17 33 Settings.Following = Model.db.profile.Following
wobin@17 34 Settings.Pending = Model.db.profile.Pending
wobin@17 35 Settings.Requested = Model.db.profile.Requested
wobin@17 36 Settings.Blocked = Model.db.profile.Blocked
wobin@17 37 Settings.Private = Model.db.profile.Private
wobin@17 38
wobin@17 39 LibStub("AceComm-3.0"):Embed(Controller)
wobin@17 40 LibStub("AceTimer-3.0"):Embed(Controller)
wobin@17 41 Controller:RegisterComm("Squawk", Controller.ReceiveMessage)
wobin@17 42 LibStub("AceConsole-3.0"):Embed(View)
wobin@17 43
wobin@17 44 end
wobin@17 45
wobin@17 46 -- Model --
wobin@17 47 --[[
wobin@17 48 --Each Squawk will have the following information:
wobin@17 49 -- * Owner (Name)
wobin@17 50 -- * Time (Epoch)
wobin@17 51 -- * Message (140 characters)
wobin@17 52 -- * ReplyTo (Name)
wobin@17 53 -- * Related (Names)
wobin@17 54 --
wobin@17 55 -- Each User will have the following lists:
wobin@17 56 -- * Follower
wobin@17 57 -- * Following
wobin@17 58 -- * Blocked
wobin@17 59 -- * Pending (Requests to follow that you haven't acted on)
wobin@17 60 -- * Requested (Requests to follow that you have made)
wobin@17 61 -- * Privacy State
wobin@17 62 --
wobin@17 63 -- A user can only request to follow an online person. Requests can be approved
wobin@17 64 -- on or offline, but the initial request must be made online.
wobin@17 65 --
wobin@17 66 -- When a user makes a request to follow a private user, the subsequent paths occur:
wobin@17 67 -- - Followee is added to Settings.Requested
wobin@17 68 -- - Followee receives 'follow request' -> (their) Settings.Pending
wobin@17 69 -- - Followee acts on request -> (their) Settings.Pending cleared
wobin@17 70 -- 1) Follwer is online
wobin@17 71 -- - Follower receives 'request accepted' -> Added to Settings.Following and
wobin@17 72 -- cleared from Settings.Requested
wobin@17 73 -- 2) Follower is offline
wobin@17 74 -- - The next time Follower is online and recieves a Squawk we check if there
wobin@17 75 -- is a Settings.Requested for that name, and if so assume they have approved
wobin@17 76 -- and clear/add records appropriately.
wobin@17 77 --
wobin@17 78 -- For updating, there can be a few methods.
wobin@17 79 --
wobin@17 80 -- Guild open: you're not private, you broadcast to the guild your last X
wobin@17 81 -- squawks on login
wobin@17 82 --
wobin@17 83 -- followers:
wobin@17 84 --]]
wobin@17 85 Model.Squawks = {}
wobin@17 86 local Squawks = Model.Squawks
wobin@17 87 Squawks.Main = {}
wobin@17 88 Squawks.Owners = {}
wobin@17 89
wobin@17 90 local function wrap(str, limit)
wobin@17 91 limit = limit or 72
wobin@17 92 local here = 1
wobin@17 93 return str:gsub("(%s+)()(%S+)()",
wobin@17 94 function(sp, st, word, fi)
wobin@17 95 if fi-here > limit then
wobin@17 96 here = st
wobin@17 97 return "\n"..word
wobin@17 98 end
wobin@17 99 end)
wobin@17 100 end
wobin@17 101
wobin@17 102 function Squawks:new(Message, Owner)
wobin@17 103 local o = {}
wobin@17 104 o.Owner = Owner or UnitName("player")
wobin@17 105 o.Message = wrap(Message)
wobin@17 106 o.Time = time()
wobin@17 107 local reply, to = strsplit("@", ((strsplit(" ", Message))))
wobin@17 108 if reply == "" then
wobin@17 109 o.ReplyTo = to
wobin@17 110 end
wobin@17 111
wobin@17 112 o.Related = {}
wobin@17 113
wobin@17 114 for word in string.gmatch(Message, "@(%a+)") do
wobin@17 115 if word ~= o.ReplyTo or "" then
wobin@17 116 table.insert(o.Related, word)
wobin@17 117 end
wobin@17 118 end
wobin@17 119
wobin@17 120 table.insert(self.Main, o)
wobin@17 121
wobin@17 122 if not self.Owners[Owner] then
wobin@17 123 self.Owners[Owner] = {}
wobin@17 124 end
wobin@17 125 table.insert(self.Owners[Owner], o)
wobin@17 126
wobin@17 127 return o
wobin@17 128 end
wobin@17 129
wobin@17 130 function Squawks:Sort(Squawks)
wobin@17 131 table.sort(Squawks or self.Main, function(a,b) return a.Time > b.Time end)
wobin@17 132 return Squawks or self.Main
wobin@17 133 end
wobin@17 134
wobin@17 135 function Squawks:GetOwn(Squawks)
wobin@17 136 local mine = {}
wobin@17 137 for _, squawk in ipairs(Squawks or self.Main) do
wobin@17 138 if squawk.Owner == UnitName("player") then
wobin@17 139 table.insert(mine, squawk)
wobin@17 140 end
wobin@17 141 end
wobin@17 142 return self:Sort(mine)
wobin@17 143 end
wobin@17 144
wobin@17 145 function Squawks:GetLast10(Squawks)
wobin@17 146 local mine = {}
wobin@17 147 Squawks = Squawks or self.Main
wobin@17 148 local limit = #Squawks < 10 and #Squawks or 10
wobin@17 149
wobin@17 150 Squawks = Squawk:Sort(Squawks)
wobin@17 151
wobin@17 152 for i=1,limit do
wobin@17 153 table.insert(mine, Squawks[i])
wobin@17 154 end
wobin@17 155 return mine
wobin@17 156 end
wobin@17 157
wobin@17 158 -- initially called with no arguments to get the latest timestamp of
wobin@17 159 -- my squawks, or with a name to find the latest timestamp of all
wobin@17 160 -- squawks from that user
wobin@17 161 function Squawks:GetLatestTimestamp(Name, Squawks)
wobin@17 162 if Name then
wobin@17 163 if self.Owners[Name] then
wobin@17 164 return self:GetLatestTimestamp(nil, self.Owners[Name])
wobin@17 165 else
wobin@17 166 return -1 -- No squawks exist for that name in our records
wobin@17 167 end
wobin@17 168 end
wobin@17 169
wobin@17 170 Squawks = Squawks or self.Main or {}
wobin@17 171 local latest = self:Sort(Squawks)
wobin@17 172 return latest and #latest > 0 and latest[1].Time or -1
wobin@17 173 end
wobin@17 174
wobin@17 175 function Squawks:GetLatestSquawks(Timestamp)
wobin@17 176 local latest = {}
wobin@17 177 for i, squawk in ipairs(self:Sort()) do
wobin@17 178 if squawk.Time > Timestamp and i < 10 then
wobin@17 179 table.insert(latest, squawk)
wobin@17 180 else
wobin@17 181 return latest
wobin@17 182 end
wobin@17 183 end
wobin@17 184 end
wobin@17 185
wobin@17 186 function Settings:IsPrivate()
wobin@17 187 return Settings.Private
wobin@17 188 end
wobin@17 189
wobin@17 190 function Settings:TogglePrivate()
wobin@17 191 Settings.Private = not Settings.Private
wobin@17 192 end
wobin@17 193
wobin@17 194 function Settings:AddFollower(Name)
wobin@17 195 Settings.Follower[Name] = 1
wobin@17 196 self:RemovePending(Name)
wobin@17 197 end
wobin@17 198
wobin@17 199 function Settings:AddFollowing(Name)
wobin@17 200 Settings.Following[Name] = 1
wobin@17 201 self:RemoveRequested(Name)
wobin@17 202 end
wobin@17 203
wobin@17 204 function Settings:AddBlock(Name)
wobin@17 205 Settings.Blocked[Name] = 1
wobin@17 206 self:RemoveFollower(Name)
wobin@17 207 self:RemoveFollowing(Name)
wobin@17 208 end
wobin@17 209
wobin@17 210 function Settings:AddPending(Name)
wobin@17 211 Settings.Pending[Name] = 1
wobin@17 212 end
wobin@17 213
wobin@17 214 function Settings:AddRequested(Name)
wobin@17 215 Settings.Requested[Name] = 1
wobin@17 216 end
wobin@17 217
wobin@17 218 function Settings:RemoveFollower(Name)
wobin@17 219 if Settings.Follower[Name] then
wobin@17 220 Settings.Follower[Name] = nil
wobin@17 221 end
wobin@17 222 end
wobin@17 223
wobin@17 224 function Settings:RemoveFollowing(Name)
wobin@17 225 if Settings.Following[Name] then
wobin@17 226 Settings.Following[Name] = nil
wobin@17 227 end
wobin@17 228 end
wobin@17 229
wobin@17 230 function Settings:RemoveBlock(Name)
wobin@17 231 if Settings.Blocked[Name] then
wobin@17 232 Settings.Blocked[Name] = nil
wobin@17 233 end
wobin@17 234 end
wobin@17 235
wobin@17 236 function Settings:RemovePending(Name)
wobin@17 237 if Settings.Pending[Name] then
wobin@17 238 Settings.Pending[Name] = nil
wobin@17 239 end
wobin@17 240 end
wobin@17 241
wobin@17 242 function Settings:RemoveRequested(Name)
wobin@17 243 if Settings.Requested[Name] then
wobin@17 244 Settings.Requested[Name] = nil
wobin@17 245 end
wobin@17 246 end
wobin@17 247
wobin@17 248 --Controller--
wobin@17 249
wobin@17 250 function Controller:TheyWantToFollowMe(Name)
wobin@17 251 if Settings:IsPrivate() then
wobin@17 252 Settings:AddPending(Name)
wobin@17 253 self:PutForwardFollowRequest(Name)
wobin@17 254 self:SendMessageToTarget(Name, "#Pending|"..UnitName("player"))
wobin@17 255 else
wobin@17 256 Settings:AddFollower(Name)
wobin@17 257 View:NotifyOfNewFollower(Name)
wobin@17 258 self:SendMessageToTarget(Name, "#Follow|"..UnitName("player"))
wobin@17 259 end
wobin@17 260 end
wobin@17 261
wobin@17 262 function Controller:TheyWantToUnfollowMe(Name)
wobin@17 263 Settings:RemoveFollower(Name)
wobin@17 264 end
wobin@17 265
wobin@17 266 function Controller:IWantToFollowThem(Name)
wobin@17 267 self:SendMessageToTarget(Name, "#Request|"..UnitName("player"))
wobin@17 268 Settings:AddRequested(Name)
wobin@17 269 end
wobin@17 270
wobin@17 271 function Controller:IWantToUnfollowThem(Name)
wobin@17 272 Settings:RemoveFollowing(Name)
wobin@17 273 self:SendMessageToTarget(Name, "#Unfollow|"..UnitName("player"))
wobin@17 274 View:NotifyOfUnfollowing(Name)
wobin@17 275 end
wobin@17 276
wobin@17 277 function Controller:IAmNowFollowingThem(Name)
wobin@17 278 Settings:AddFollowing(Name)
wobin@17 279 View:NotifyOfNewFollowing(Name)
wobin@17 280 end
wobin@17 281
wobin@17 282 function Controller:AddANewSquawk(Name, Message, Source)
wobin@17 283 if not Settings.Blocked[Name] then
wobin@17 284
wobin@17 285 if Source == "WHISPER" then
wobin@17 286 if Settings.Requested[Name] then -- We've been approved offline!
wobin@17 287 Settings:AddFollowing(Name)
wobin@17 288 end
wobin@17 289
wobin@17 290 if not Settings.Following[Name] then -- If we're no longer following this person
wobin@17 291 self:SendMessageToTarget(Name, "#Unfollow|"..UnitName("player"))
wobin@17 292 return
wobin@17 293 end
wobin@17 294 end
wobin@17 295
wobin@17 296 if Source == "GUILD" and Name == UnitName("player") then
wobin@17 297 return
wobin@17 298 end
wobin@17 299
wobin@17 300 table.insert(Model.Squawks, Squawk:new(Message, Name))
wobin@17 301 View:UpdateSquawkList()
wobin@17 302 end
wobin@17 303 end
wobin@17 304
wobin@17 305 local trigger
wobin@17 306 local function RepressFailure(frame, event, ...)
wobin@17 307 if arg1:match(string.gsub(ERR_CHAT_PLAYER_NOT_FOUND_S, "%%s", "(.*)")) then
wobin@17 308 if trigger then Controller:CancelTimer(trigger, true) end
wobin@17 309 trigger = Controller:ScheduleTimer(
wobin@17 310 function()
wobin@17 311 ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", RepressFailure)
wobin@17 312 end, 3) -- Give it three seconds and then remove the filter.
wobin@17 313 return true
wobin@17 314 else
wobin@17 315 return false, unpack(...)
wobin@17 316 end
wobin@17 317 end
wobin@17 318
wobin@17 319 function Controller:SendNewSquawk(Message)
wobin@17 320 if not Settings:IsPrivate() then
wobin@17 321 self:SendMessageToGuild("#Squawk|"..UnitName("player").."|"..Message)
wobin@17 322 end
wobin@17 323
wobin@17 324 self:AddANewSquawk(UnitName("player"), Message)
wobin@17 325 for name, _ in pairs(Settings.Following) do
wobin@17 326 self:SendMessageToTarget(name, "#Squawk|"..UnitName("player").."|"..Message)
wobin@17 327 end
wobin@17 328 end
wobin@17 329
wobin@17 330 function Controller:ImPending(Name)
wobin@17 331 View:NotifyOfPending(Name)
wobin@17 332 end
wobin@17 333
wobin@17 334 function Controller:PutForwardFollowRequest(Name)
wobin@17 335 View:NotifyOfPendingRequest(Name)
wobin@17 336 end
wobin@17 337
wobin@17 338 function Controller:ApprovePendingRequest(Name)
wobin@17 339 Settings:AddFollower(Name)
wobin@17 340 View:NotifyOfNewFollower(Name)
wobin@17 341 self:SendMessageToTarget(Name, "#Follow|"..UnitName("player"))
wobin@17 342 end
wobin@17 343
wobin@17 344
wobin@17 345
wobin@17 346 function Controller:SendMessageToTarget(Name, Message)
wobin@17 347 ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", RepressFailure)
wobin@17 348 self:SendCommMessage("Squawk", Message, "WHISPER", Name)
wobin@17 349 end
wobin@17 350
wobin@17 351 function Controller:SendMessageToGuild(Message)
wobin@17 352 self:SendCommMessage("Squawk", Message, "GUILD")
wobin@17 353 end
wobin@17 354
wobin@17 355 local Parse = {
wobin@17 356 ["#Pending"] = Controller.ImPending,
wobin@17 357 ["#Follow"] = Controller.IAmNowFollowingThem,
wobin@17 358 ["#Unfollow"] = Controller.TheyWantToUnfollowMe,
wobin@17 359 ["#Squawk"] = Controller.AddANewSquawk,
wobin@17 360 ["#Request"] = Controller.TheyWantToFollowMe,
wobin@17 361 }
wobin@17 362
wobin@17 363 function Controller:ReceiveMessage(Message, Distribution, Sender)
wobin@17 364 local command, name, info = strsplit("|",Message)
wobin@17 365 View:Print(Distribution..":"..Message)
wobin@17 366 Parse[command](Controller, name, info, Distribution)
wobin@17 367 end
wobin@17 368
wobin@17 369 -- View --
wobin@17 370
wobin@17 371 function View:UpdateSquawkList()
wobin@17 372 self:Print("Updated Squawk List")
wobin@17 373 self:ShowMeMySquawks()
wobin@17 374 end
wobin@17 375
wobin@17 376 function View:NotifyOfPending(Name)
wobin@17 377 self:Print(Name.." will have to approve your request")
wobin@17 378 end
wobin@17 379
wobin@17 380 function View:NotifyOfPendingRequest(Name)
wobin@17 381 self:Print(Name.." wants to follow you.")
wobin@17 382 end
wobin@17 383
wobin@17 384 function View:NotifyOfNewFollowing(Name)
wobin@17 385 self:Print("You are now following "..Name)
wobin@17 386 end
wobin@17 387
wobin@17 388 function View:NotifyOfUnfollowing(Name)
wobin@17 389 self:Print("You are no longer following "..Name)
wobin@17 390 end
wobin@17 391
wobin@17 392 function View:NotifyOfNewFollower(Name)
wobin@17 393 self:Print(Name.." is now following you")
wobin@17 394 end
wobin@17 395
wobin@17 396 function View:ShowMeMySquawks()
wobin@17 397 for _,squawk in ipairs(Model.Squawks.Main) do
wobin@17 398 self:Print(squawk.Message)
wobin@17 399 end
wobin@17 400 end
wobin@17 401
wobin@17 402 function View:ShowMeMyFollowers()
wobin@17 403 self:Print("My followers are:")
wobin@17 404 for name,_ in pairs(Settings.Follower) do
wobin@17 405 self:Print(name)
wobin@17 406 end
wobin@17 407 end
wobin@17 408
wobin@17 409 function View:ShowMeWhoImFollowing()
wobin@17 410 self:Print("I am following:")
wobin@17 411 for name,_ in pairs(Settings.Following) do
wobin@17 412 self:Print(name)
wobin@17 413 end
wobin@17 414 end
wobin@17 415
wobin@17 416 function View:ShowMeWhoIveBlocked()
wobin@17 417 self:Print("I've blocked:")
wobin@17 418 for name,_ in pairs(Settings.Blocked) do
wobin@17 419 self:Print(name)
wobin@17 420 end
wobin@17 421 end
wobin@17 422
wobin@17 423 local TimeSpan = { [1] = {"second", 60, 1},
wobin@17 424 [2] = {"minute", 3600, 60},
wobin@17 425 [3] = {"hour", 86400, 3600} }
wobin@17 426
wobin@17 427 function View:GetTime(stime)
wobin@17 428 local lapsed = difftime(time(), stime)
wobin@17 429 if lapsed < 86400 then -- if we're still in the same day...
wobin@17 430 for _,span in ipairs(TimeSpan) do
wobin@17 431 if lapsed < span[2] then
wobin@17 432 local timespan = math.floor(lapsed/span[3])
wobin@17 433 if timespan == 1 then
wobin@17 434 timespan = timespan .." ".. span[1]
wobin@17 435 else
wobin@17 436 timespan = timespan .. " ".. span[1].."s"
wobin@17 437 end
wobin@17 438 return timespan.. " ago"
wobin@17 439 end
wobin@17 440 end
wobin@17 441 end
wobin@17 442 return date("%I:%M %p %b %d", stime)
wobin@17 443 end
wobin@17 444
wobin@17 445 local LDBFeed = LibStub("LibDataBroker-1.1"):NewDataObject("Squawk", {type = "data source", text = "Awk!"})
wobin@17 446 local QTip = LibStub("LibQTip-1.0")
wobin@17 447 local QTipClick = LibStub("LibQTipClick-1.0")
wobin@17 448 local tooltip = {}
wobin@17 449
wobin@17 450 local function HideTooltip()
wobin@17 451 if MouseIsOver(tooltip) then return end
wobin@17 452 tooltip:SetScript("OnLeave", nil)
wobin@17 453 tooltip:Hide()
wobin@17 454 QTip:Release(tooltip)
wobin@17 455 tooltip = nil
wobin@17 456 end
wobin@17 457
wobin@17 458 local function ReplyToMe(cell, Owner, event)
wobin@17 459 View:Print("Replying to @"..Owner)
wobin@17 460 end
wobin@17 461
wobin@17 462 local function AddLine(tooltip, Line, Number, Owner, TimeStamp)
wobin@17 463 local x,y
wobin@17 464 if #Line < 79 then
wobin@17 465 y,x = tooltip:AddNormalLine(Number, Owner, Line, TimeStamp)
wobin@17 466 else
wobin@17 467 y,x = tooltip:AddNormalLine(Number, Owner, Line:sub(1, 80).."-", TimeStamp)
wobin@17 468 AddLine(tooltip, Line:sub(81))
wobin@17 469 end
wobin@17 470 if not TimeStamp then return end
wobin@17 471
wobin@17 472 -- Now add the reply clickback
wobin@17 473 tooltip:SetCell(y, 5, " ", Owner)
wobin@17 474 tooltip.lines[y].cells[5]:SetBackdrop({bgFile= "Interface\\Addons\\Squawk\\reply"})
wobin@17 475 if not tooltip.lines[y].cells[5]:GetScript("OnHide") then
wobin@17 476 tooltip.lines[y].cells[5]:SetScript("OnHide", function(self) self:SetBackdrop(nil) self:SetScript("OnHide", nil) end)
wobin@17 477 end
wobin@17 478 -- Reply clickback finished
wobin@17 479 end
wobin@17 480
wobin@17 481 function LDBFeed:OnEnter()
wobin@17 482 tooltip = QTipClick:Acquire("Squawk",5, "LEFT", "CENTER", "LEFT", "RIGHT", "RIGHT")
wobin@17 483 tooltip:Clear()
wobin@17 484 tooltip:SetCallback("OnMouseDown", ReplyToMe)
wobin@17 485 self.tooltip = tooltip
wobin@17 486 for i,squawk in ipairs(Squawk:GetLast10(Model.Squawks)) do
wobin@17 487 local head = true
wobin@17 488 local message = {strsplit("\n",squawk.Message)}
wobin@17 489 for _,line in ipairs(message) do
wobin@17 490 if head then
wobin@17 491 AddLine(tooltip, line, i..".", squawk.Owner, View:GetTime(squawk.Time))
wobin@17 492 head = false
wobin@17 493 else
wobin@17 494 AddLine(tooltip, line)
wobin@17 495 end
wobin@17 496 end
wobin@17 497 end
wobin@17 498 tooltip:SmartAnchorTo(self)
wobin@17 499 tooltip:SetScript("OnLeave", HideTooltip)
wobin@17 500 tooltip:Show()
wobin@17 501 end
wobin@17 502
wobin@17 503 function LDBFeed:OnLeave()
wobin@17 504 HideTooltip()
wobin@17 505 end
wobin@17 506 --[[
wobin@17 507
wobin@17 508 function LDBFeed:OnClick(button)
wobin@17 509 editbox:ClearAllPoints()
wobin@17 510 editbox:SetPoint(GetTipAnchor(self))
wobin@17 511 editbox:Show()
wobin@17 512 end
wobin@17 513
wobin@17 514 local function GetTipAnchor(frame)
wobin@17 515 if not x or not y then return "TOPLEFT", frame, "BOTTOMLEFT" end
wobin@17 516 local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or ""
wobin@17 517 local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM"
wobin@17 518 return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
wobin@17 519 end
wobin@17 520
wobin@17 521 local editbox = CreateFrame('EditBox', nil, UIParent)
wobin@17 522 editbox:Hide()
wobin@17 523 editbox:SetAutoFocus(true)
wobin@17 524 editbox:SetHeight(32)
wobin@17 525 editbox:SetWidth(350)
wobin@17 526 editbox:SetFrameStrata("HIGH")
wobin@17 527 editbox:SetFontObject('GameFontHighlightSmall')
wobin@17 528 lib.editbox = editbox
wobin@17 529
wobin@17 530 editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
wobin@17 531 editbox:SetScript("OnEnterPressed", editbox.ClearFocus)
wobin@17 532 editbox:SetScript("OnEditFocusLost", editbox.Hide)
wobin@17 533 editbox:SetScript("OnEditFocusGained", editbox.HighlightText)
wobin@17 534 editbox:SetScript("OnTextChanged", function(self)
wobin@17 535 self:SetText(self:GetParent().val)
wobin@17 536 self:HighlightText()
wobin@17 537 end)
wobin@17 538
wobin@17 539 local left = editbox:CreateTexture(nil, "BACKGROUND")
wobin@17 540 left:SetWidth(8) left:SetHeight(20)
wobin@17 541 left:SetPoint("LEFT", -5, 0)
wobin@17 542 left:SetTexture("Interface\\Common\\Common-Input-Border")
wobin@17 543 left:SetTexCoord(0, 0.0625, 0, 0.625)
wobin@17 544
wobin@17 545 local right = editbox:CreateTexture(nil, "BACKGROUND")
wobin@17 546 right:SetWidth(8) right:SetHeight(20)
wobin@17 547 right:SetPoint("RIGHT", 0, 0)
wobin@17 548 right:SetTexture("Interface\\Common\\Common-Input-Border")
wobin@17 549 right:SetTexCoord(0.9375, 1, 0, 0.625)
wobin@17 550
wobin@17 551 local center = editbox:CreateTexture(nil, "BACKGROUND")
wobin@17 552 center:SetHeight(20)
wobin@17 553 center:SetPoint("RIGHT", right, "LEFT", 0, 0)
wobin@17 554 center:SetPoint("LEFT", left, "RIGHT", 0, 0)
wobin@17 555 center:SetTexture("Interface\\Common\\Common-Input-Border")
wobin@17 556 center:SetTexCoord(0.0625, 0.9375, 0, 0.625)
wobin@17 557
wobin@17 558 function lib.OpenEditbox(self)
wobin@17 559 editbox:SetText(self.val)
wobin@17 560 editbox:SetParent(self)
wobin@17 561 editbox:SetPoint("LEFT", self)
wobin@17 562 editbox:SetPoint("RIGHT", self)
wobin@17 563 editbox:Show()
wobin@17 564 end
wobin@17 565 --]]
wobin@17 566