annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown.lua @ 15:21cefa363c73 tip

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