annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown.lua @ 25:ac501d71c890 tip

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