annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown.lua @ 59:8a4c1438dbdf

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