annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown.lua @ 3:c6f0976069c7

Default value for the welcome / bye notification is now set to false The mailframe checkbox now primarily toggles the mail opening, however if you hold shift you can still disable the entire addon Now properly removes QuickAuction?s mail count Now tracks when a mail lost all attachments rather than it being deleted in order to continue processing the next item (mail sent by players containing text should now work properly). This should also be good for a nice speed increase. Added a variable called ?busy? to the MailOpener object indicating whether or not Mail Opener is currently working. Other addons (or macros) can retrieve it with ?LibStub("AceAddon-3.0"):GetAddon("MailOpener").busy? A mail refresh from the Postal service should no longer occur while mail is being opened but will happen instantly afterwards. Postal?s module toggling will now be handled by Postal itself. Added a short summary to the top of all modules for other developers. The time remaining until next mail box refresh should be displayed for as long as Mail Opener can be sure.
author Zerotorescue
date Tue, 07 Sep 2010 17:46:27 +0200
parents 823e33465b6e
children
rev   line source
Zerotorescue@0 1 --[[ $Id: AceGUIWidget-DropDown.lua 916 2010-03-15 12:24:36Z nevcairiel $ ]]--
Zerotorescue@0 2 local AceGUI = LibStub("AceGUI-3.0")
Zerotorescue@0 3
Zerotorescue@0 4 -- Lua APIs
Zerotorescue@0 5 local min, max, floor = math.min, math.max, math.floor
Zerotorescue@0 6 local select, pairs, ipairs = select, pairs, ipairs
Zerotorescue@0 7 local tsort = table.sort
Zerotorescue@0 8
Zerotorescue@0 9 -- WoW APIs
Zerotorescue@0 10 local PlaySound = PlaySound
Zerotorescue@0 11 local UIParent, CreateFrame = UIParent, CreateFrame
Zerotorescue@0 12 local _G = _G
Zerotorescue@0 13
Zerotorescue@0 14 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
Zerotorescue@0 15 -- List them here for Mikk's FindGlobals script
Zerotorescue@0 16 -- GLOBALS: CLOSE
Zerotorescue@0 17
Zerotorescue@0 18 local function fixlevels(parent,...)
Zerotorescue@0 19 local i = 1
Zerotorescue@0 20 local child = select(i, ...)
Zerotorescue@0 21 while child do
Zerotorescue@0 22 child:SetFrameLevel(parent:GetFrameLevel()+1)
Zerotorescue@0 23 fixlevels(child, child:GetChildren())
Zerotorescue@0 24 i = i + 1
Zerotorescue@0 25 child = select(i, ...)
Zerotorescue@0 26 end
Zerotorescue@0 27 end
Zerotorescue@0 28
Zerotorescue@0 29 local function fixstrata(strata, parent, ...)
Zerotorescue@0 30 local i = 1
Zerotorescue@0 31 local child = select(i, ...)
Zerotorescue@0 32 parent:SetFrameStrata(strata)
Zerotorescue@0 33 while child do
Zerotorescue@0 34 fixstrata(strata, child, child:GetChildren())
Zerotorescue@0 35 i = i + 1
Zerotorescue@0 36 child = select(i, ...)
Zerotorescue@0 37 end
Zerotorescue@0 38 end
Zerotorescue@0 39
Zerotorescue@0 40 do
Zerotorescue@0 41 local widgetType = "Dropdown-Pullout"
Zerotorescue@0 42 local widgetVersion = 3
Zerotorescue@0 43
Zerotorescue@0 44 --[[ Static data ]]--
Zerotorescue@0 45
Zerotorescue@0 46 local backdrop = {
Zerotorescue@0 47 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
Zerotorescue@0 48 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
Zerotorescue@0 49 edgeSize = 32,
Zerotorescue@0 50 tileSize = 32,
Zerotorescue@0 51 tile = true,
Zerotorescue@0 52 insets = { left = 11, right = 12, top = 12, bottom = 11 },
Zerotorescue@0 53 }
Zerotorescue@0 54 local sliderBackdrop = {
Zerotorescue@0 55 bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
Zerotorescue@0 56 edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
Zerotorescue@0 57 tile = true, tileSize = 8, edgeSize = 8,
Zerotorescue@0 58 insets = { left = 3, right = 3, top = 3, bottom = 3 }
Zerotorescue@0 59 }
Zerotorescue@0 60
Zerotorescue@0 61 local defaultWidth = 200
Zerotorescue@0 62 local defaultMaxHeight = 600
Zerotorescue@0 63
Zerotorescue@0 64 --[[ UI Event Handlers ]]--
Zerotorescue@0 65
Zerotorescue@0 66 -- HACK: This should be no part of the pullout, but there
Zerotorescue@0 67 -- is no other 'clean' way to response to any item-OnEnter
Zerotorescue@0 68 -- Used to close Submenus when an other item is entered
Zerotorescue@0 69 local function OnEnter(item)
Zerotorescue@0 70 local self = item.pullout
Zerotorescue@0 71 for k, v in ipairs(self.items) do
Zerotorescue@0 72 if v.CloseMenu and v ~= item then
Zerotorescue@0 73 v:CloseMenu()
Zerotorescue@0 74 end
Zerotorescue@0 75 end
Zerotorescue@0 76 end
Zerotorescue@0 77
Zerotorescue@0 78 -- See the note in Constructor() for each scroll related function
Zerotorescue@0 79 local function OnMouseWheel(this, value)
Zerotorescue@0 80 this.obj:MoveScroll(value)
Zerotorescue@0 81 end
Zerotorescue@0 82
Zerotorescue@0 83 local function OnScrollValueChanged(this, value)
Zerotorescue@0 84 this.obj:SetScroll(value)
Zerotorescue@0 85 end
Zerotorescue@0 86
Zerotorescue@0 87 local function OnSizeChanged(this)
Zerotorescue@0 88 this.obj:FixScroll()
Zerotorescue@0 89 end
Zerotorescue@0 90
Zerotorescue@0 91 --[[ Exported methods ]]--
Zerotorescue@0 92
Zerotorescue@0 93 -- exported
Zerotorescue@0 94 local function SetScroll(self, value)
Zerotorescue@0 95 local status = self.scrollStatus
Zerotorescue@0 96 local frame, child = self.scrollFrame, self.itemFrame
Zerotorescue@0 97 local height, viewheight = frame:GetHeight(), child:GetHeight()
Zerotorescue@0 98
Zerotorescue@0 99 local offset
Zerotorescue@0 100 if height > viewheight then
Zerotorescue@0 101 offset = 0
Zerotorescue@0 102 else
Zerotorescue@0 103 offset = floor((viewheight - height) / 1000 * value)
Zerotorescue@0 104 end
Zerotorescue@0 105 child:ClearAllPoints()
Zerotorescue@0 106 child:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, offset)
Zerotorescue@0 107 child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", self.slider:IsShown() and -12 or 0, offset)
Zerotorescue@0 108 status.offset = offset
Zerotorescue@0 109 status.scrollvalue = value
Zerotorescue@0 110 end
Zerotorescue@0 111
Zerotorescue@0 112 -- exported
Zerotorescue@0 113 local function MoveScroll(self, value)
Zerotorescue@0 114 local status = self.scrollStatus
Zerotorescue@0 115 local frame, child = self.scrollFrame, self.itemFrame
Zerotorescue@0 116 local height, viewheight = frame:GetHeight(), child:GetHeight()
Zerotorescue@0 117
Zerotorescue@0 118 if height > viewheight then
Zerotorescue@0 119 self.slider:Hide()
Zerotorescue@0 120 else
Zerotorescue@0 121 self.slider:Show()
Zerotorescue@0 122 local diff = height - viewheight
Zerotorescue@0 123 local delta = 1
Zerotorescue@0 124 if value < 0 then
Zerotorescue@0 125 delta = -1
Zerotorescue@0 126 end
Zerotorescue@0 127 self.slider:SetValue(min(max(status.scrollvalue + delta*(1000/(diff/45)),0), 1000))
Zerotorescue@0 128 end
Zerotorescue@0 129 end
Zerotorescue@0 130
Zerotorescue@0 131 -- exported
Zerotorescue@0 132 local function FixScroll(self)
Zerotorescue@0 133 local status = self.scrollStatus
Zerotorescue@0 134 local frame, child = self.scrollFrame, self.itemFrame
Zerotorescue@0 135 local height, viewheight = frame:GetHeight(), child:GetHeight()
Zerotorescue@0 136 local offset = status.offset or 0
Zerotorescue@0 137
Zerotorescue@0 138 if viewheight < height then
Zerotorescue@0 139 self.slider:Hide()
Zerotorescue@0 140 child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, offset)
Zerotorescue@0 141 self.slider:SetValue(0)
Zerotorescue@0 142 else
Zerotorescue@0 143 self.slider:Show()
Zerotorescue@0 144 local value = (offset / (viewheight - height) * 1000)
Zerotorescue@0 145 if value > 1000 then value = 1000 end
Zerotorescue@0 146 self.slider:SetValue(value)
Zerotorescue@0 147 self:SetScroll(value)
Zerotorescue@0 148 if value < 1000 then
Zerotorescue@0 149 child:ClearAllPoints()
Zerotorescue@0 150 child:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, offset)
Zerotorescue@0 151 child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -12, offset)
Zerotorescue@0 152 status.offset = offset
Zerotorescue@0 153 end
Zerotorescue@0 154 end
Zerotorescue@0 155 end
Zerotorescue@0 156
Zerotorescue@0 157 -- exported, AceGUI callback
Zerotorescue@0 158 local function OnAcquire(self)
Zerotorescue@0 159 self.frame:SetParent(UIParent)
Zerotorescue@0 160 --self.itemFrame:SetToplevel(true)
Zerotorescue@0 161 end
Zerotorescue@0 162
Zerotorescue@0 163 -- exported, AceGUI callback
Zerotorescue@0 164 local function OnRelease(self)
Zerotorescue@0 165 self:Clear()
Zerotorescue@0 166 self.frame:ClearAllPoints()
Zerotorescue@0 167 self.frame:Hide()
Zerotorescue@0 168 end
Zerotorescue@0 169
Zerotorescue@0 170 -- exported
Zerotorescue@0 171 local function AddItem(self, item)
Zerotorescue@0 172 self.items[#self.items + 1] = item
Zerotorescue@0 173
Zerotorescue@0 174 local h = #self.items * 16
Zerotorescue@0 175 self.itemFrame:SetHeight(h)
Zerotorescue@0 176 self.frame:SetHeight(min(h + 34, self.maxHeight)) -- +34: 20 for scrollFrame placement (10 offset) and +14 for item placement
Zerotorescue@0 177
Zerotorescue@0 178 item.frame:SetPoint("LEFT", self.itemFrame, "LEFT")
Zerotorescue@0 179 item.frame:SetPoint("RIGHT", self.itemFrame, "RIGHT")
Zerotorescue@0 180
Zerotorescue@0 181 item:SetPullout(self)
Zerotorescue@0 182 item:SetOnEnter(OnEnter)
Zerotorescue@0 183 end
Zerotorescue@0 184
Zerotorescue@0 185 -- exported
Zerotorescue@0 186 local function Open(self, point, relFrame, relPoint, x, y)
Zerotorescue@0 187 local items = self.items
Zerotorescue@0 188 local frame = self.frame
Zerotorescue@0 189 local itemFrame = self.itemFrame
Zerotorescue@0 190
Zerotorescue@0 191 frame:SetPoint(point, relFrame, relPoint, x, y)
Zerotorescue@0 192
Zerotorescue@0 193
Zerotorescue@0 194 local height = 8
Zerotorescue@0 195 for i, item in pairs(items) do
Zerotorescue@0 196 if i == 1 then
Zerotorescue@0 197 item:SetPoint("TOP", itemFrame, "TOP", 0, -2)
Zerotorescue@0 198 else
Zerotorescue@0 199 item:SetPoint("TOP", items[i-1].frame, "BOTTOM", 0, 1)
Zerotorescue@0 200 end
Zerotorescue@0 201
Zerotorescue@0 202 item:Show()
Zerotorescue@0 203
Zerotorescue@0 204 height = height + 16
Zerotorescue@0 205 end
Zerotorescue@0 206 itemFrame:SetHeight(height)
Zerotorescue@0 207 fixstrata("TOOLTIP", frame, frame:GetChildren())
Zerotorescue@0 208 frame:Show()
Zerotorescue@0 209 self:Fire("OnOpen")
Zerotorescue@0 210 end
Zerotorescue@0 211
Zerotorescue@0 212 -- exported
Zerotorescue@0 213 local function Close(self)
Zerotorescue@0 214 self.frame:Hide()
Zerotorescue@0 215 self:Fire("OnClose")
Zerotorescue@0 216 end
Zerotorescue@0 217
Zerotorescue@0 218 -- exported
Zerotorescue@0 219 local function Clear(self)
Zerotorescue@0 220 local items = self.items
Zerotorescue@0 221 for i, item in pairs(items) do
Zerotorescue@0 222 AceGUI:Release(item)
Zerotorescue@0 223 items[i] = nil
Zerotorescue@0 224 end
Zerotorescue@0 225 end
Zerotorescue@0 226
Zerotorescue@0 227 -- exported
Zerotorescue@0 228 local function IterateItems(self)
Zerotorescue@0 229 return ipairs(self.items)
Zerotorescue@0 230 end
Zerotorescue@0 231
Zerotorescue@0 232 -- exported
Zerotorescue@0 233 local function SetHideOnLeave(self, val)
Zerotorescue@0 234 self.hideOnLeave = val
Zerotorescue@0 235 end
Zerotorescue@0 236
Zerotorescue@0 237 -- exported
Zerotorescue@0 238 local function SetMaxHeight(self, height)
Zerotorescue@0 239 self.maxHeight = height or defaultMaxHeight
Zerotorescue@0 240 if self.frame:GetHeight() > height then
Zerotorescue@0 241 self.frame:SetHeight(height)
Zerotorescue@0 242 elseif (self.itemFrame:GetHeight() + 34) < height then
Zerotorescue@0 243 self.frame:SetHeight(self.itemFrame:GetHeight() + 34) -- see :AddItem
Zerotorescue@0 244 end
Zerotorescue@0 245 end
Zerotorescue@0 246
Zerotorescue@0 247 -- exported
Zerotorescue@0 248 local function GetRightBorderWidth(self)
Zerotorescue@0 249 return 6 + (self.slider:IsShown() and 12 or 0)
Zerotorescue@0 250 end
Zerotorescue@0 251
Zerotorescue@0 252 -- exported
Zerotorescue@0 253 local function GetLeftBorderWidth(self)
Zerotorescue@0 254 return 6
Zerotorescue@0 255 end
Zerotorescue@0 256
Zerotorescue@0 257 --[[ Constructor ]]--
Zerotorescue@0 258
Zerotorescue@0 259 local function Constructor()
Zerotorescue@0 260 local count = AceGUI:GetNextWidgetNum(widgetType)
Zerotorescue@0 261 local frame = CreateFrame("Frame", "AceGUI30Pullout"..count, UIParent)
Zerotorescue@0 262 local self = {}
Zerotorescue@0 263 self.count = count
Zerotorescue@0 264 self.type = widgetType
Zerotorescue@0 265 self.frame = frame
Zerotorescue@0 266 frame.obj = self
Zerotorescue@0 267
Zerotorescue@0 268 self.OnAcquire = OnAcquire
Zerotorescue@0 269 self.OnRelease = OnRelease
Zerotorescue@0 270
Zerotorescue@0 271 self.AddItem = AddItem
Zerotorescue@0 272 self.Open = Open
Zerotorescue@0 273 self.Close = Close
Zerotorescue@0 274 self.Clear = Clear
Zerotorescue@0 275 self.IterateItems = IterateItems
Zerotorescue@0 276 self.SetHideOnLeave = SetHideOnLeave
Zerotorescue@0 277
Zerotorescue@0 278 self.SetScroll = SetScroll
Zerotorescue@0 279 self.MoveScroll = MoveScroll
Zerotorescue@0 280 self.FixScroll = FixScroll
Zerotorescue@0 281
Zerotorescue@0 282 self.SetMaxHeight = SetMaxHeight
Zerotorescue@0 283 self.GetRightBorderWidth = GetRightBorderWidth
Zerotorescue@0 284 self.GetLeftBorderWidth = GetLeftBorderWidth
Zerotorescue@0 285
Zerotorescue@0 286 self.items = {}
Zerotorescue@0 287
Zerotorescue@0 288 self.scrollStatus = {
Zerotorescue@0 289 scrollvalue = 0,
Zerotorescue@0 290 }
Zerotorescue@0 291
Zerotorescue@0 292 self.maxHeight = defaultMaxHeight
Zerotorescue@0 293
Zerotorescue@0 294 frame:SetBackdrop(backdrop)
Zerotorescue@0 295 frame:SetBackdropColor(0, 0, 0)
Zerotorescue@0 296 frame:SetFrameStrata("FULLSCREEN_DIALOG")
Zerotorescue@0 297 frame:SetClampedToScreen(true)
Zerotorescue@0 298 frame:SetWidth(defaultWidth)
Zerotorescue@0 299 frame:SetHeight(self.maxHeight)
Zerotorescue@0 300 --frame:SetToplevel(true)
Zerotorescue@0 301
Zerotorescue@0 302 -- NOTE: The whole scroll frame code is copied from the AceGUI-3.0 widget ScrollFrame
Zerotorescue@0 303 local scrollFrame = CreateFrame("ScrollFrame", nil, frame)
Zerotorescue@0 304 local itemFrame = CreateFrame("Frame", nil, scrollFrame)
Zerotorescue@0 305
Zerotorescue@0 306 self.scrollFrame = scrollFrame
Zerotorescue@0 307 self.itemFrame = itemFrame
Zerotorescue@0 308
Zerotorescue@0 309 scrollFrame.obj = self
Zerotorescue@0 310 itemFrame.obj = self
Zerotorescue@0 311
Zerotorescue@0 312 local slider = CreateFrame("Slider", "AceGUI30PulloutScrollbar"..count, scrollFrame)
Zerotorescue@0 313 slider:SetOrientation("VERTICAL")
Zerotorescue@0 314 slider:SetHitRectInsets(0, 0, -10, 0)
Zerotorescue@0 315 slider:SetBackdrop(sliderBackdrop)
Zerotorescue@0 316 slider:SetWidth(8)
Zerotorescue@0 317 slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Vertical")
Zerotorescue@0 318 slider:SetFrameStrata("FULLSCREEN_DIALOG")
Zerotorescue@0 319 self.slider = slider
Zerotorescue@0 320 slider.obj = self
Zerotorescue@0 321
Zerotorescue@0 322 scrollFrame:SetScrollChild(itemFrame)
Zerotorescue@0 323 scrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 6, -12)
Zerotorescue@0 324 scrollFrame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -6, 12)
Zerotorescue@0 325 scrollFrame:EnableMouseWheel(true)
Zerotorescue@0 326 scrollFrame:SetScript("OnMouseWheel", OnMouseWheel)
Zerotorescue@0 327 scrollFrame:SetScript("OnSizeChanged", OnSizeChanged)
Zerotorescue@0 328 scrollFrame:SetToplevel(true)
Zerotorescue@0 329 scrollFrame:SetFrameStrata("FULLSCREEN_DIALOG")
Zerotorescue@0 330
Zerotorescue@0 331 itemFrame:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 0, 0)
Zerotorescue@0 332 itemFrame:SetPoint("TOPRIGHT", scrollFrame, "TOPRIGHT", -12, 0)
Zerotorescue@0 333 itemFrame:SetHeight(400)
Zerotorescue@0 334 itemFrame:SetToplevel(true)
Zerotorescue@0 335 itemFrame:SetFrameStrata("FULLSCREEN_DIALOG")
Zerotorescue@0 336
Zerotorescue@0 337 slider:SetPoint("TOPLEFT", scrollFrame, "TOPRIGHT", -16, 0)
Zerotorescue@0 338 slider:SetPoint("BOTTOMLEFT", scrollFrame, "BOTTOMRIGHT", -16, 0)
Zerotorescue@0 339 slider:SetScript("OnValueChanged", OnScrollValueChanged)
Zerotorescue@0 340 slider:SetMinMaxValues(0, 1000)
Zerotorescue@0 341 slider:SetValueStep(1)
Zerotorescue@0 342 slider:SetValue(0)
Zerotorescue@0 343
Zerotorescue@0 344 scrollFrame:Show()
Zerotorescue@0 345 itemFrame:Show()
Zerotorescue@0 346 slider:Hide()
Zerotorescue@0 347
Zerotorescue@0 348 self:FixScroll()
Zerotorescue@0 349
Zerotorescue@0 350 AceGUI:RegisterAsWidget(self)
Zerotorescue@0 351 return self
Zerotorescue@0 352 end
Zerotorescue@0 353
Zerotorescue@0 354 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)
Zerotorescue@0 355 end
Zerotorescue@0 356
Zerotorescue@0 357 do
Zerotorescue@0 358 local widgetType = "Dropdown"
Zerotorescue@0 359 local widgetVersion = 22
Zerotorescue@0 360
Zerotorescue@0 361 --[[ Static data ]]--
Zerotorescue@0 362
Zerotorescue@0 363 --[[ UI event handler ]]--
Zerotorescue@0 364
Zerotorescue@0 365 local function Control_OnEnter(this)
Zerotorescue@0 366 this.obj:Fire("OnEnter")
Zerotorescue@0 367 end
Zerotorescue@0 368
Zerotorescue@0 369 local function Control_OnLeave(this)
Zerotorescue@0 370 this.obj:Fire("OnLeave")
Zerotorescue@0 371 end
Zerotorescue@0 372
Zerotorescue@0 373 local function Dropdown_OnHide(this)
Zerotorescue@0 374 local self = this.obj
Zerotorescue@0 375 if self.open then
Zerotorescue@0 376 self.pullout:Close()
Zerotorescue@0 377 end
Zerotorescue@0 378 end
Zerotorescue@0 379
Zerotorescue@0 380 local function Dropdown_TogglePullout(this)
Zerotorescue@0 381 local self = this.obj
Zerotorescue@0 382 PlaySound("igMainMenuOptionCheckBoxOn") -- missleading name, but the Blizzard code uses this sound
Zerotorescue@0 383 if self.open then
Zerotorescue@0 384 self.open = nil
Zerotorescue@0 385 self.pullout:Close()
Zerotorescue@0 386 AceGUI:ClearFocus()
Zerotorescue@0 387 else
Zerotorescue@0 388 self.open = true
Zerotorescue@0 389 self.pullout:SetWidth(self.frame:GetWidth())
Zerotorescue@0 390 self.pullout:Open("TOPLEFT", self.frame, "BOTTOMLEFT", 0, self.label:IsShown() and -2 or 0)
Zerotorescue@0 391 AceGUI:SetFocus(self)
Zerotorescue@0 392 end
Zerotorescue@0 393 end
Zerotorescue@0 394
Zerotorescue@0 395 local function OnPulloutOpen(this)
Zerotorescue@0 396 local self = this.userdata.obj
Zerotorescue@0 397 local value = self.value
Zerotorescue@0 398
Zerotorescue@0 399 if not self.multiselect then
Zerotorescue@0 400 for i, item in this:IterateItems() do
Zerotorescue@0 401 item:SetValue(item.userdata.value == value)
Zerotorescue@0 402 end
Zerotorescue@0 403 end
Zerotorescue@0 404
Zerotorescue@0 405 self.open = true
Zerotorescue@0 406 end
Zerotorescue@0 407
Zerotorescue@0 408 local function OnPulloutClose(this)
Zerotorescue@0 409 local self = this.userdata.obj
Zerotorescue@0 410 self.open = nil
Zerotorescue@0 411 self:Fire("OnClosed")
Zerotorescue@0 412 end
Zerotorescue@0 413
Zerotorescue@0 414 local function ShowMultiText(self)
Zerotorescue@0 415 local text
Zerotorescue@0 416 for i, widget in self.pullout:IterateItems() do
Zerotorescue@0 417 if widget.type == "Dropdown-Item-Toggle" then
Zerotorescue@0 418 if widget:GetValue() then
Zerotorescue@0 419 if text then
Zerotorescue@0 420 text = text..", "..widget:GetText()
Zerotorescue@0 421 else
Zerotorescue@0 422 text = widget:GetText()
Zerotorescue@0 423 end
Zerotorescue@0 424 end
Zerotorescue@0 425 end
Zerotorescue@0 426 end
Zerotorescue@0 427 self:SetText(text)
Zerotorescue@0 428 end
Zerotorescue@0 429
Zerotorescue@0 430 local function OnItemValueChanged(this, event, checked)
Zerotorescue@0 431 local self = this.userdata.obj
Zerotorescue@0 432
Zerotorescue@0 433 if self.multiselect then
Zerotorescue@0 434 self:Fire("OnValueChanged", this.userdata.value, checked)
Zerotorescue@0 435 ShowMultiText(self)
Zerotorescue@0 436 else
Zerotorescue@0 437 if checked then
Zerotorescue@0 438 self:SetValue(this.userdata.value)
Zerotorescue@0 439 self:Fire("OnValueChanged", this.userdata.value)
Zerotorescue@0 440 else
Zerotorescue@0 441 this:SetValue(true)
Zerotorescue@0 442 end
Zerotorescue@0 443 if self.open then
Zerotorescue@0 444 self.pullout:Close()
Zerotorescue@0 445 end
Zerotorescue@0 446 end
Zerotorescue@0 447 end
Zerotorescue@0 448
Zerotorescue@0 449 --[[ Exported methods ]]--
Zerotorescue@0 450
Zerotorescue@0 451 -- exported, AceGUI callback
Zerotorescue@0 452 local function OnAcquire(self)
Zerotorescue@0 453 local pullout = AceGUI:Create("Dropdown-Pullout")
Zerotorescue@0 454 self.pullout = pullout
Zerotorescue@0 455 pullout.userdata.obj = self
Zerotorescue@0 456 pullout:SetCallback("OnClose", OnPulloutClose)
Zerotorescue@0 457 pullout:SetCallback("OnOpen", OnPulloutOpen)
Zerotorescue@0 458 self.pullout.frame:SetFrameLevel(self.frame:GetFrameLevel() + 1)
Zerotorescue@0 459 fixlevels(self.pullout.frame, self.pullout.frame:GetChildren())
Zerotorescue@0 460
Zerotorescue@0 461 self:SetHeight(44)
Zerotorescue@0 462 self:SetWidth(200)
Zerotorescue@0 463 end
Zerotorescue@0 464
Zerotorescue@0 465 -- exported, AceGUI callback
Zerotorescue@0 466 local function OnRelease(self)
Zerotorescue@0 467 if self.open then
Zerotorescue@0 468 self.pullout:Close()
Zerotorescue@0 469 end
Zerotorescue@0 470 AceGUI:Release(self.pullout)
Zerotorescue@0 471 self.pullout = nil
Zerotorescue@0 472
Zerotorescue@0 473 self:SetText("")
Zerotorescue@0 474 self:SetLabel("")
Zerotorescue@0 475 self:SetDisabled(false)
Zerotorescue@0 476 self:SetMultiselect(false)
Zerotorescue@0 477
Zerotorescue@0 478 self.value = nil
Zerotorescue@0 479 self.list = nil
Zerotorescue@0 480 self.open = nil
Zerotorescue@0 481 self.hasClose = nil
Zerotorescue@0 482
Zerotorescue@0 483 self.frame:ClearAllPoints()
Zerotorescue@0 484 self.frame:Hide()
Zerotorescue@0 485 end
Zerotorescue@0 486
Zerotorescue@0 487 -- exported
Zerotorescue@0 488 local function SetDisabled(self, disabled)
Zerotorescue@0 489 self.disabled = disabled
Zerotorescue@0 490 if disabled then
Zerotorescue@0 491 self.text:SetTextColor(0.5,0.5,0.5)
Zerotorescue@0 492 self.button:Disable()
Zerotorescue@0 493 self.label:SetTextColor(0.5,0.5,0.5)
Zerotorescue@0 494 else
Zerotorescue@0 495 self.button:Enable()
Zerotorescue@0 496 self.label:SetTextColor(1,.82,0)
Zerotorescue@0 497 self.text:SetTextColor(1,1,1)
Zerotorescue@0 498 end
Zerotorescue@0 499 end
Zerotorescue@0 500
Zerotorescue@0 501 -- exported
Zerotorescue@0 502 local function ClearFocus(self)
Zerotorescue@0 503 if self.open then
Zerotorescue@0 504 self.pullout:Close()
Zerotorescue@0 505 end
Zerotorescue@0 506 end
Zerotorescue@0 507
Zerotorescue@0 508 -- exported
Zerotorescue@0 509 local function SetText(self, text)
Zerotorescue@0 510 self.text:SetText(text or "")
Zerotorescue@0 511 end
Zerotorescue@0 512
Zerotorescue@0 513 -- exported
Zerotorescue@0 514 local function SetLabel(self, text)
Zerotorescue@0 515 if text and text ~= "" then
Zerotorescue@0 516 self.label:SetText(text)
Zerotorescue@0 517 self.label:Show()
Zerotorescue@0 518 self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,-18)
Zerotorescue@0 519 self.frame:SetHeight(44)
Zerotorescue@0 520 else
Zerotorescue@0 521 self.label:SetText("")
Zerotorescue@0 522 self.label:Hide()
Zerotorescue@0 523 self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,0)
Zerotorescue@0 524 self.frame:SetHeight(26)
Zerotorescue@0 525 end
Zerotorescue@0 526 end
Zerotorescue@0 527
Zerotorescue@0 528 -- exported
Zerotorescue@0 529 local function SetValue(self, value)
Zerotorescue@0 530 if self.list then
Zerotorescue@0 531 self:SetText(self.list[value] or "")
Zerotorescue@0 532 end
Zerotorescue@0 533 self.value = value
Zerotorescue@0 534 end
Zerotorescue@0 535
Zerotorescue@0 536 -- exported
Zerotorescue@0 537 local function GetValue(self)
Zerotorescue@0 538 return self.value
Zerotorescue@0 539 end
Zerotorescue@0 540
Zerotorescue@0 541 -- exported
Zerotorescue@0 542 local function SetItemValue(self, item, value)
Zerotorescue@0 543 if not self.multiselect then return end
Zerotorescue@0 544 for i, widget in self.pullout:IterateItems() do
Zerotorescue@0 545 if widget.userdata.value == item then
Zerotorescue@0 546 if widget.SetValue then
Zerotorescue@0 547 widget:SetValue(value)
Zerotorescue@0 548 end
Zerotorescue@0 549 end
Zerotorescue@0 550 end
Zerotorescue@0 551 ShowMultiText(self)
Zerotorescue@0 552 end
Zerotorescue@0 553
Zerotorescue@0 554 -- exported
Zerotorescue@0 555 local function SetItemDisabled(self, item, disabled)
Zerotorescue@0 556 for i, widget in self.pullout:IterateItems() do
Zerotorescue@0 557 if widget.userdata.value == item then
Zerotorescue@0 558 widget:SetDisabled(disabled)
Zerotorescue@0 559 end
Zerotorescue@0 560 end
Zerotorescue@0 561 end
Zerotorescue@0 562
Zerotorescue@0 563 local function AddListItem(self, value, text)
Zerotorescue@0 564 local item = AceGUI:Create("Dropdown-Item-Toggle")
Zerotorescue@0 565 item:SetText(text)
Zerotorescue@0 566 item.userdata.obj = self
Zerotorescue@0 567 item.userdata.value = value
Zerotorescue@0 568 item:SetCallback("OnValueChanged", OnItemValueChanged)
Zerotorescue@0 569 self.pullout:AddItem(item)
Zerotorescue@0 570 end
Zerotorescue@0 571
Zerotorescue@0 572 local function AddCloseButton(self)
Zerotorescue@0 573 if not self.hasClose then
Zerotorescue@0 574 local close = AceGUI:Create("Dropdown-Item-Execute")
Zerotorescue@0 575 close:SetText(CLOSE)
Zerotorescue@0 576 self.pullout:AddItem(close)
Zerotorescue@0 577 self.hasClose = true
Zerotorescue@0 578 end
Zerotorescue@0 579 end
Zerotorescue@0 580
Zerotorescue@0 581 -- exported
Zerotorescue@0 582 local sortlist = {}
Zerotorescue@0 583 local function SetList(self, list)
Zerotorescue@0 584 self.list = list
Zerotorescue@0 585 self.pullout:Clear()
Zerotorescue@0 586 self.hasClose = nil
Zerotorescue@0 587 if not list then return end
Zerotorescue@0 588
Zerotorescue@0 589 for v in pairs(list) do
Zerotorescue@0 590 sortlist[#sortlist + 1] = v
Zerotorescue@0 591 end
Zerotorescue@0 592 tsort(sortlist)
Zerotorescue@0 593
Zerotorescue@0 594 for i, value in pairs(sortlist) do
Zerotorescue@0 595 AddListItem(self, value, list[value])
Zerotorescue@0 596 sortlist[i] = nil
Zerotorescue@0 597 end
Zerotorescue@0 598 if self.multiselect then
Zerotorescue@0 599 ShowMultiText(self)
Zerotorescue@0 600 AddCloseButton(self)
Zerotorescue@0 601 end
Zerotorescue@0 602 end
Zerotorescue@0 603
Zerotorescue@0 604 -- exported
Zerotorescue@0 605 local function AddItem(self, value, text)
Zerotorescue@0 606 if self.list then
Zerotorescue@0 607 self.list[value] = text
Zerotorescue@0 608 AddListItem(self, value, text)
Zerotorescue@0 609 end
Zerotorescue@0 610 end
Zerotorescue@0 611
Zerotorescue@0 612 -- exported
Zerotorescue@0 613 local function SetMultiselect(self, multi)
Zerotorescue@0 614 self.multiselect = multi
Zerotorescue@0 615 if multi then
Zerotorescue@0 616 ShowMultiText(self)
Zerotorescue@0 617 AddCloseButton(self)
Zerotorescue@0 618 end
Zerotorescue@0 619 end
Zerotorescue@0 620
Zerotorescue@0 621 -- exported
Zerotorescue@0 622 local function GetMultiselect(self)
Zerotorescue@0 623 return self.multiselect
Zerotorescue@0 624 end
Zerotorescue@0 625
Zerotorescue@0 626 --[[ Constructor ]]--
Zerotorescue@0 627
Zerotorescue@0 628 local function Constructor()
Zerotorescue@0 629 local count = AceGUI:GetNextWidgetNum(widgetType)
Zerotorescue@0 630 local frame = CreateFrame("Frame", nil, UIParent)
Zerotorescue@0 631 local dropdown = CreateFrame("Frame", "AceGUI30DropDown"..count, frame, "UIDropDownMenuTemplate")
Zerotorescue@0 632
Zerotorescue@0 633 local self = {}
Zerotorescue@0 634 self.type = widgetType
Zerotorescue@0 635 self.frame = frame
Zerotorescue@0 636 self.dropdown = dropdown
Zerotorescue@0 637 self.count = count
Zerotorescue@0 638 frame.obj = self
Zerotorescue@0 639 dropdown.obj = self
Zerotorescue@0 640
Zerotorescue@0 641 self.OnRelease = OnRelease
Zerotorescue@0 642 self.OnAcquire = OnAcquire
Zerotorescue@0 643
Zerotorescue@0 644 self.ClearFocus = ClearFocus
Zerotorescue@0 645
Zerotorescue@0 646 self.SetText = SetText
Zerotorescue@0 647 self.SetValue = SetValue
Zerotorescue@0 648 self.GetValue = GetValue
Zerotorescue@0 649 self.SetList = SetList
Zerotorescue@0 650 self.SetLabel = SetLabel
Zerotorescue@0 651 self.SetDisabled = SetDisabled
Zerotorescue@0 652 self.AddItem = AddItem
Zerotorescue@0 653 self.SetMultiselect = SetMultiselect
Zerotorescue@0 654 self.GetMultiselect = GetMultiselect
Zerotorescue@0 655 self.SetItemValue = SetItemValue
Zerotorescue@0 656 self.SetItemDisabled = SetItemDisabled
Zerotorescue@0 657
Zerotorescue@0 658 self.alignoffset = 31
Zerotorescue@0 659
Zerotorescue@0 660 frame:SetHeight(44)
Zerotorescue@0 661 frame:SetWidth(200)
Zerotorescue@0 662 frame:SetScript("OnHide",Dropdown_OnHide)
Zerotorescue@0 663
Zerotorescue@0 664 dropdown:ClearAllPoints()
Zerotorescue@0 665 dropdown:SetPoint("TOPLEFT",frame,"TOPLEFT",-15,0)
Zerotorescue@0 666 dropdown:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",17,0)
Zerotorescue@0 667 dropdown:SetScript("OnHide", nil)
Zerotorescue@0 668
Zerotorescue@0 669 local left = _G[dropdown:GetName() .. "Left"]
Zerotorescue@0 670 local middle = _G[dropdown:GetName() .. "Middle"]
Zerotorescue@0 671 local right = _G[dropdown:GetName() .. "Right"]
Zerotorescue@0 672
Zerotorescue@0 673 middle:ClearAllPoints()
Zerotorescue@0 674 right:ClearAllPoints()
Zerotorescue@0 675
Zerotorescue@0 676 middle:SetPoint("LEFT", left, "RIGHT", 0, 0)
Zerotorescue@0 677 middle:SetPoint("RIGHT", right, "LEFT", 0, 0)
Zerotorescue@0 678 right:SetPoint("TOPRIGHT", dropdown, "TOPRIGHT", 0, 17)
Zerotorescue@0 679
Zerotorescue@0 680 local button = _G[dropdown:GetName() .. "Button"]
Zerotorescue@0 681 self.button = button
Zerotorescue@0 682 button.obj = self
Zerotorescue@0 683 button:SetScript("OnEnter",Control_OnEnter)
Zerotorescue@0 684 button:SetScript("OnLeave",Control_OnLeave)
Zerotorescue@0 685 button:SetScript("OnClick",Dropdown_TogglePullout)
Zerotorescue@0 686
Zerotorescue@0 687 local text = _G[dropdown:GetName() .. "Text"]
Zerotorescue@0 688 self.text = text
Zerotorescue@0 689 text.obj = self
Zerotorescue@0 690 text:ClearAllPoints()
Zerotorescue@0 691 text:SetPoint("RIGHT", right, "RIGHT" ,-43, 2)
Zerotorescue@0 692 text:SetPoint("LEFT", left, "LEFT", 25, 2)
Zerotorescue@0 693
Zerotorescue@0 694 local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
Zerotorescue@0 695 label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
Zerotorescue@0 696 label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0)
Zerotorescue@0 697 label:SetJustifyH("LEFT")
Zerotorescue@0 698 label:SetHeight(18)
Zerotorescue@0 699 label:Hide()
Zerotorescue@0 700 self.label = label
Zerotorescue@0 701
Zerotorescue@0 702 AceGUI:RegisterAsWidget(self)
Zerotorescue@0 703 return self
Zerotorescue@0 704 end
Zerotorescue@0 705
Zerotorescue@0 706 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)
Zerotorescue@0 707 end