Mercurial > wow > hansgar_and_franzok_assist
comparison Libs/DF/dropdown.lua @ 11:2f09fe4be15c
Added an Options Panel.
| author | Tercio |
|---|---|
| date | Mon, 20 Apr 2015 16:34:18 -0300 |
| parents | |
| children | 0c160948ac5e |
comparison
equal
deleted
inserted
replaced
| 10:f1e32be6773e | 11:2f09fe4be15c |
|---|---|
| 1 | |
| 2 local DF = _G ["DetailsFramework"] | |
| 3 local _ | |
| 4 | |
| 5 local _rawset = rawset --> lua local | |
| 6 local _rawget = rawget --> lua local | |
| 7 local _setmetatable = setmetatable --> lua local | |
| 8 local _unpack = unpack --> lua local | |
| 9 local _type = type --> lua local | |
| 10 local _math_floor = math.floor --> lua local | |
| 11 local loadstring = loadstring --> lua local | |
| 12 local _string_len = string.len --> lua local | |
| 13 | |
| 14 local cleanfunction = function() end | |
| 15 local APIDropDownFunctions = false | |
| 16 local DropDownMetaFunctions = {} | |
| 17 | |
| 18 ------------------------------------------------------------------------------------------------------------ | |
| 19 --> metatables | |
| 20 | |
| 21 DropDownMetaFunctions.__call = function (_table, value) | |
| 22 --> unknow | |
| 23 end | |
| 24 | |
| 25 ------------------------------------------------------------------------------------------------------------ | |
| 26 --> members | |
| 27 | |
| 28 --> selected value | |
| 29 local gmember_value = function (_object) | |
| 30 return _object:GetValue() | |
| 31 end | |
| 32 --> tooltip | |
| 33 local gmember_tooltip = function (_object) | |
| 34 return _object:GetTooltip() | |
| 35 end | |
| 36 --> shown | |
| 37 local gmember_shown = function (_object) | |
| 38 return _object:IsShown() | |
| 39 end | |
| 40 --> frame width | |
| 41 local gmember_width = function (_object) | |
| 42 return _object.button:GetWidth() | |
| 43 end | |
| 44 --> frame height | |
| 45 local gmember_height = function (_object) | |
| 46 return _object.button:GetHeight() | |
| 47 end | |
| 48 --> current text | |
| 49 local gmember_text = function (_object) | |
| 50 return _object.label:GetText() | |
| 51 end | |
| 52 --> menu creation function | |
| 53 local gmember_function = function (_object) | |
| 54 return _object:GetFunction() | |
| 55 end | |
| 56 --> menu width | |
| 57 local gmember_menuwidth = function (_object) | |
| 58 return _rawget (self, "realsizeW") | |
| 59 end | |
| 60 --> menu height | |
| 61 local gmember_menuheight = function (_object) | |
| 62 return _rawget (self, "realsizeH") | |
| 63 end | |
| 64 | |
| 65 local get_members_function_index = { | |
| 66 ["value"] = gmember_value, | |
| 67 ["text"] = gmember_text, | |
| 68 ["shown"] = gmember_shown, | |
| 69 ["width"] = gmember_width, | |
| 70 ["menuwidth"] = gmember_menuwidth, | |
| 71 ["height"] = gmember_height, | |
| 72 ["menuheight"] = gmember_menuheight, | |
| 73 ["tooltip"] = gmember_tooltip, | |
| 74 ["func"] = gmember_function, | |
| 75 } | |
| 76 | |
| 77 DropDownMetaFunctions.__index = function (_table, _member_requested) | |
| 78 | |
| 79 local func = get_members_function_index [_member_requested] | |
| 80 if (func) then | |
| 81 return func (_table, _member_requested) | |
| 82 end | |
| 83 | |
| 84 local fromMe = _rawget (_table, _member_requested) | |
| 85 if (fromMe) then | |
| 86 return fromMe | |
| 87 end | |
| 88 | |
| 89 return DropDownMetaFunctions [_member_requested] | |
| 90 end | |
| 91 | |
| 92 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 93 | |
| 94 --> tooltip | |
| 95 local smember_tooltip = function (_object, _value) | |
| 96 return _object:SetTooltip (_value) | |
| 97 end | |
| 98 --> show | |
| 99 local smember_show = function (_object, _value) | |
| 100 if (_value) then | |
| 101 return _object:Show() | |
| 102 else | |
| 103 return _object:Hide() | |
| 104 end | |
| 105 end | |
| 106 --> hide | |
| 107 local smember_hide = function (_object, _value) | |
| 108 if (not _value) then | |
| 109 return _object:Show() | |
| 110 else | |
| 111 return _object:Hide() | |
| 112 end | |
| 113 end | |
| 114 --> frame width | |
| 115 local smember_width = function (_object, _value) | |
| 116 return _object.dropdown:SetWidth (_value) | |
| 117 end | |
| 118 --> frame height | |
| 119 local smember_height = function (_object, _value) | |
| 120 return _object.dropdown:SetHeight (_value) | |
| 121 end | |
| 122 --> menu creation function | |
| 123 local smember_function = function (_object, _value) | |
| 124 return _object:SetFunction (_value) | |
| 125 end | |
| 126 --> menu width | |
| 127 local smember_menuwidth = function (_object, _value) | |
| 128 _object:SetMenuSize (_value, nil) | |
| 129 end | |
| 130 --> menu height | |
| 131 local smember_menuheight = function (_object, _value) | |
| 132 _object:SetMenuSize (nil, _value) | |
| 133 end | |
| 134 | |
| 135 local set_members_function_index = { | |
| 136 ["tooltip"] = smember_tooltip, | |
| 137 ["show"] = smember_show, | |
| 138 ["hide"] = smember_hide, | |
| 139 ["width"] = smember_width, | |
| 140 ["menuwidth"] = smember_menuwidth, | |
| 141 ["height"] = smember_height, | |
| 142 ["menuheight"] = smember_menuheight, | |
| 143 ["func"] = smember_function, | |
| 144 } | |
| 145 | |
| 146 DropDownMetaFunctions.__newindex = function (_table, _key, _value) | |
| 147 local func = set_members_function_index [_key] | |
| 148 if (func) then | |
| 149 return func (_table, _value) | |
| 150 else | |
| 151 return _rawset (_table, _key, _value) | |
| 152 end | |
| 153 end | |
| 154 | |
| 155 ------------------------------------------------------------------------------------------------------------ | |
| 156 --> methods | |
| 157 function DropDownMetaFunctions:IsShown() | |
| 158 return self.dropdown:IsShown() | |
| 159 end | |
| 160 function DropDownMetaFunctions:Show() | |
| 161 return self.dropdown:Show() | |
| 162 end | |
| 163 function DropDownMetaFunctions:Hide() | |
| 164 return self.dropdown:Hide() | |
| 165 end | |
| 166 | |
| 167 --> menu width and height | |
| 168 function DropDownMetaFunctions:SetMenuSize (w, h) | |
| 169 if (w) then | |
| 170 return _rawset (self, "realsizeW", w) | |
| 171 end | |
| 172 if (h) then | |
| 173 return _rawset (self, "realsizeH", h) | |
| 174 end | |
| 175 end | |
| 176 function DropDownMetaFunctions:GetMenuSize() | |
| 177 return _rawget (self, "realsizeW"), _rawget (self, "realsizeH") | |
| 178 end | |
| 179 | |
| 180 --> function | |
| 181 function DropDownMetaFunctions:SetFunction (func) | |
| 182 return _rawset (self, "func", func) | |
| 183 end | |
| 184 function DropDownMetaFunctions:GetFunction() | |
| 185 return _rawget (self, "func") | |
| 186 end | |
| 187 | |
| 188 --> value | |
| 189 function DropDownMetaFunctions:GetValue() | |
| 190 return _rawget (self, "myvalue") | |
| 191 end | |
| 192 function DropDownMetaFunctions:SetValue (value) | |
| 193 return _rawset (self, "myvalue", value) | |
| 194 end | |
| 195 | |
| 196 --> setpoint | |
| 197 function DropDownMetaFunctions:SetPoint (v1, v2, v3, v4, v5) | |
| 198 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self) | |
| 199 if (not v1) then | |
| 200 print ("Invalid parameter for SetPoint") | |
| 201 return | |
| 202 end | |
| 203 return self.widget:SetPoint (v1, v2, v3, v4, v5) | |
| 204 end | |
| 205 | |
| 206 --> sizes | |
| 207 function DropDownMetaFunctions:SetSize (w, h) | |
| 208 if (w) then | |
| 209 self.dropdown:SetWidth (w) | |
| 210 end | |
| 211 if (h) then | |
| 212 return self.dropdown:SetHeight (h) | |
| 213 end | |
| 214 end | |
| 215 | |
| 216 --> tooltip | |
| 217 function DropDownMetaFunctions:SetTooltip (tooltip) | |
| 218 if (tooltip) then | |
| 219 return _rawset (self, "have_tooltip", tooltip) | |
| 220 else | |
| 221 return _rawset (self, "have_tooltip", nil) | |
| 222 end | |
| 223 end | |
| 224 function DropDownMetaFunctions:GetTooltip() | |
| 225 return _rawget (self, "have_tooltip") | |
| 226 end | |
| 227 | |
| 228 --> frame levels | |
| 229 function DropDownMetaFunctions:GetFrameLevel() | |
| 230 return self.dropdown:GetFrameLevel() | |
| 231 end | |
| 232 function DropDownMetaFunctions:SetFrameLevel (level, frame) | |
| 233 if (not frame) then | |
| 234 return self.dropdown:SetFrameLevel (level) | |
| 235 else | |
| 236 local framelevel = frame:GetFrameLevel (frame) + level | |
| 237 return self.dropdown:SetFrameLevel (framelevel) | |
| 238 end | |
| 239 end | |
| 240 | |
| 241 --> frame stratas | |
| 242 function DropDownMetaFunctions:GetFrameStrata() | |
| 243 return self.dropdown:GetFrameStrata() | |
| 244 end | |
| 245 function DropDownMetaFunctions:SetFrameStrata (strata) | |
| 246 if (_type (strata) == "table") then | |
| 247 self.dropdown:SetFrameStrata (strata:GetFrameStrata()) | |
| 248 else | |
| 249 self.dropdown:SetFrameStrata (strata) | |
| 250 end | |
| 251 end | |
| 252 | |
| 253 --> enabled | |
| 254 function DropDownMetaFunctions:IsEnabled() | |
| 255 return self.dropdown:IsEnabled() | |
| 256 end | |
| 257 | |
| 258 function DropDownMetaFunctions:Enable() | |
| 259 | |
| 260 self:SetAlpha (1) | |
| 261 _rawset (self, "lockdown", false) | |
| 262 | |
| 263 if (self.OnEnable) then | |
| 264 self.OnEnable (self) | |
| 265 end | |
| 266 --return self.dropdown:Enable() | |
| 267 end | |
| 268 | |
| 269 function DropDownMetaFunctions:Disable() | |
| 270 | |
| 271 self:SetAlpha (.4) | |
| 272 _rawset (self, "lockdown", true) | |
| 273 | |
| 274 if (self.OnDisable) then | |
| 275 self.OnDisable (self) | |
| 276 end | |
| 277 --return self.dropdown:Disable() | |
| 278 end | |
| 279 | |
| 280 --> fixed value | |
| 281 function DropDownMetaFunctions:SetFixedParameter (value) | |
| 282 _rawset (self, "FixedValue", value) | |
| 283 end | |
| 284 | |
| 285 --> hooks | |
| 286 function DropDownMetaFunctions:SetHook (hookType, func) | |
| 287 if (func) then | |
| 288 _rawset (self, hookType.."Hook", func) | |
| 289 else | |
| 290 _rawset (self, hookType.."Hook", nil) | |
| 291 end | |
| 292 end | |
| 293 | |
| 294 ------------------------------------------------------------------------------------------------------------ | |
| 295 --> scripts | |
| 296 | |
| 297 local last_opened = false | |
| 298 | |
| 299 local function isOptionVisible (thisOption) | |
| 300 if (_type (thisOption.shown) == "boolean" or _type (thisOption.shown) == "function") then | |
| 301 if (not thisOption.shown) then | |
| 302 return false | |
| 303 elseif (not thisOption.shown()) then | |
| 304 return false | |
| 305 end | |
| 306 end | |
| 307 return true | |
| 308 end | |
| 309 | |
| 310 function DropDownMetaFunctions:Refresh() | |
| 311 local menu = self.func() | |
| 312 | |
| 313 if (#menu == 0) then | |
| 314 self:NoOption (true) | |
| 315 self.no_options = true | |
| 316 return false | |
| 317 | |
| 318 elseif (self.no_options) then | |
| 319 self.no_options = false | |
| 320 self:NoOption (false) | |
| 321 self:NoOptionSelected() | |
| 322 return true | |
| 323 end | |
| 324 | |
| 325 return true | |
| 326 end | |
| 327 | |
| 328 function DropDownMetaFunctions:NoOptionSelected() | |
| 329 self.label:SetText (self.empty_text or "no option selected") | |
| 330 self.label:SetTextColor (1, 1, 1, 0.4) | |
| 331 if (self.empty_icon) then | |
| 332 self.icon:SetTexture (self.empty_icon) | |
| 333 else | |
| 334 self.icon:SetTexture ([[Interface\COMMON\UI-ModelControlPanel]]) | |
| 335 self.icon:SetTexCoord (0.625, 0.78125, 0.328125, 0.390625) | |
| 336 end | |
| 337 self.icon:SetVertexColor (1, 1, 1, 0.4) | |
| 338 | |
| 339 self.last_select = nil | |
| 340 end | |
| 341 | |
| 342 function DropDownMetaFunctions:NoOption (state) | |
| 343 if (state) then | |
| 344 self:Disable() | |
| 345 self:SetAlpha (0.5) | |
| 346 self.no_options = true | |
| 347 self.label:SetText ("no options") | |
| 348 self.label:SetTextColor (1, 1, 1, 0.4) | |
| 349 self.icon:SetTexture ([[Interface\CHARACTERFRAME\UI-Player-PlayTimeUnhealthy]]) | |
| 350 self.icon:SetTexCoord (0, 1, 0, 1) | |
| 351 self.icon:SetVertexColor (1, 1, 1, 0.4) | |
| 352 else | |
| 353 self.no_options = false | |
| 354 self:Enable() | |
| 355 self:SetAlpha (1) | |
| 356 end | |
| 357 end | |
| 358 | |
| 359 function DropDownMetaFunctions:Select (optionName, byOptionNumber) | |
| 360 | |
| 361 if (type (optionName) == "boolean" and not optionName) then | |
| 362 self:NoOptionSelected() | |
| 363 return false | |
| 364 end | |
| 365 | |
| 366 local menu = self.func() | |
| 367 | |
| 368 if (#menu == 0) then | |
| 369 self:NoOption (true) | |
| 370 return true | |
| 371 else | |
| 372 self:NoOption (false) | |
| 373 end | |
| 374 | |
| 375 if (byOptionNumber and type (optionName) == "number") then | |
| 376 if (not menu [optionName]) then --> invalid index | |
| 377 self:NoOptionSelected() | |
| 378 return false | |
| 379 end | |
| 380 self:Selected (menu [optionName]) | |
| 381 return true | |
| 382 end | |
| 383 | |
| 384 for _, thisMenu in ipairs (menu) do | |
| 385 if ( ( thisMenu.label == optionName or thisMenu.value == optionName ) and isOptionVisible (thisMenu)) then | |
| 386 self:Selected (thisMenu) | |
| 387 return true | |
| 388 end | |
| 389 end | |
| 390 | |
| 391 return false | |
| 392 end | |
| 393 | |
| 394 function DropDownMetaFunctions:SetEmptyTextAndIcon (text, icon) | |
| 395 if (text) then | |
| 396 self.empty_text = text | |
| 397 end | |
| 398 if (icon) then | |
| 399 self.empty_icon = icon | |
| 400 end | |
| 401 | |
| 402 self:Selected (self.last_select) | |
| 403 end | |
| 404 | |
| 405 function DropDownMetaFunctions:Selected (_table) | |
| 406 | |
| 407 if (not _table) then | |
| 408 | |
| 409 --> there is any options? | |
| 410 if (not self:Refresh()) then | |
| 411 self.last_select = nil | |
| 412 return | |
| 413 end | |
| 414 | |
| 415 --> exists options but none selected | |
| 416 self:NoOptionSelected() | |
| 417 return | |
| 418 end | |
| 419 | |
| 420 self.last_select = _table | |
| 421 self:NoOption (false) | |
| 422 | |
| 423 self.label:SetText (_table.label) | |
| 424 self.icon:SetTexture (_table.icon) | |
| 425 | |
| 426 if (_table.icon) then | |
| 427 self.label:SetPoint ("left", self.icon, "right", 2, 0) | |
| 428 if (_table.texcoord) then | |
| 429 self.icon:SetTexCoord (unpack (_table.texcoord)) | |
| 430 else | |
| 431 self.icon:SetTexCoord (0, 1, 0, 1) | |
| 432 end | |
| 433 | |
| 434 if (_table.iconcolor) then | |
| 435 if (type (_table.iconcolor) == "string") then | |
| 436 self.icon:SetVertexColor (DF:ParseColors (_table.iconcolor)) | |
| 437 else | |
| 438 self.icon:SetVertexColor (unpack (_table.iconcolor)) | |
| 439 end | |
| 440 else | |
| 441 self.icon:SetVertexColor (1, 1, 1, 1) | |
| 442 end | |
| 443 | |
| 444 else | |
| 445 self.label:SetPoint ("left", self.label:GetParent(), "left", 4, 0) | |
| 446 end | |
| 447 | |
| 448 self.statusbar:SetTexture (_table.statusbar) | |
| 449 | |
| 450 if (_table.color) then | |
| 451 local _value1, _value2, _value3, _value4 = DF:ParseColors (_table.color) | |
| 452 self.label:SetTextColor (_value1, _value2, _value3, _value4) | |
| 453 else | |
| 454 self.label:SetTextColor (1, 1, 1, 1) | |
| 455 end | |
| 456 | |
| 457 if (_table.font) then | |
| 458 self.label:SetFont (_table.font, 10) | |
| 459 else | |
| 460 self.label:SetFont ("GameFontHighlightSmall", 10) | |
| 461 end | |
| 462 | |
| 463 self:SetValue (_table.value) | |
| 464 | |
| 465 end | |
| 466 | |
| 467 function DetailsFrameworkDropDownOptionClick (button) | |
| 468 | |
| 469 --> update name and icon on main frame | |
| 470 button.object:Selected (button.table) | |
| 471 | |
| 472 --> close menu frame | |
| 473 button.object:Close() | |
| 474 | |
| 475 --> exec function if any | |
| 476 if (button.table.onclick) then | |
| 477 button.table.onclick (button:GetParent():GetParent():GetParent().MyObject, button.object.FixedValue, button.table.value) | |
| 478 end | |
| 479 | |
| 480 --> set the value of selected option in main object | |
| 481 button.object.myvalue = button.table.value | |
| 482 end | |
| 483 | |
| 484 function DropDownMetaFunctions:Open() | |
| 485 self.dropdown.dropdownframe:Show() | |
| 486 self.dropdown.dropdownborder:Show() | |
| 487 self.dropdown.arrowTexture:SetTexture ("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Down") | |
| 488 self.opened = true | |
| 489 if (last_opened) then | |
| 490 last_opened:Close() | |
| 491 end | |
| 492 last_opened = self | |
| 493 end | |
| 494 | |
| 495 function DropDownMetaFunctions:Close() | |
| 496 --> when menu is being close, just hide the border and the script will call back this again | |
| 497 if (self.dropdown.dropdownborder:IsShown()) then | |
| 498 self.dropdown.dropdownborder:Hide() | |
| 499 return | |
| 500 end | |
| 501 self.dropdown.dropdownframe:Hide() | |
| 502 self.dropdown.arrowTexture:SetTexture ("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up") | |
| 503 | |
| 504 local selectedTexture = _G [self:GetName() .. "_ScrollFrame_ScrollChild_SelectedTexture"] | |
| 505 selectedTexture:Hide() | |
| 506 | |
| 507 self.opened = false | |
| 508 last_opened = false | |
| 509 end | |
| 510 | |
| 511 --> close by escape key | |
| 512 function DetailsFrameworkDropDownOptionsFrameOnHide (frame) | |
| 513 frame:GetParent().MyObject:Close() | |
| 514 end | |
| 515 | |
| 516 function DetailsFrameworkDropDownOptionOnEnter (frame) | |
| 517 if (frame.table.desc) then | |
| 518 DF:CooltipPreset (2) | |
| 519 GameCooltip2:AddLine (frame.table.desc) | |
| 520 if (frame.table.descfont) then | |
| 521 GameCooltip2:SetOption ("TextFont", frame.table.descfont) | |
| 522 end | |
| 523 | |
| 524 GameCooltip2:SetHost (frame, "topleft", "topright", 10, 0) | |
| 525 | |
| 526 GameCooltip2:ShowCooltip (nil, "tooltip") | |
| 527 frame.tooltip = true | |
| 528 end | |
| 529 frame:GetParent().mouseover:SetPoint ("left", frame) | |
| 530 frame:GetParent().mouseover:Show() | |
| 531 end | |
| 532 | |
| 533 function DetailsFrameworkDropDownOptionOnLeave (frame) | |
| 534 if (frame.table.desc) then | |
| 535 GameCooltip2:ShowMe (false) | |
| 536 end | |
| 537 frame:GetParent().mouseover:Hide() | |
| 538 end | |
| 539 | |
| 540 function DetailsFrameworkDropDownOnMouseDown (button) | |
| 541 | |
| 542 local object = button.MyObject | |
| 543 | |
| 544 if (not object.opened and not _rawget (object, "lockdown")) then --> click to open | |
| 545 | |
| 546 local menu = object:func() | |
| 547 object.builtMenu = menu | |
| 548 | |
| 549 local frame_witdh = object.realsizeW | |
| 550 | |
| 551 if (menu [1]) then | |
| 552 --> build menu | |
| 553 | |
| 554 local scrollFrame = _G [button:GetName() .. "_ScrollFrame"] | |
| 555 local scrollChild = _G [button:GetName() .. "_ScrollFrame_ScrollChild"] | |
| 556 local scrollBorder = _G [button:GetName() .. "_Border"] | |
| 557 local selectedTexture = _G [button:GetName() .. "_ScrollFrame_ScrollChild_SelectedTexture"] | |
| 558 local mouseOverTexture = _G [button:GetName() .. "_ScrollFrame_ScrollChild_MouseOverTexture"] | |
| 559 | |
| 560 local i = 1 | |
| 561 local showing = 0 | |
| 562 local currentText = button.text:GetText() or "" | |
| 563 | |
| 564 if (object.OnMouseDownHook) then | |
| 565 local interrupt = object.OnMouseDownHook (button, buttontype, menu, scrollFrame, scrollChild, selectedTexture) | |
| 566 if (interrupt) then | |
| 567 return | |
| 568 end | |
| 569 end | |
| 570 | |
| 571 for _, _table in ipairs (menu) do | |
| 572 | |
| 573 local show = isOptionVisible (_table) | |
| 574 | |
| 575 if (show) then | |
| 576 local _this_row = object.menus [i] | |
| 577 showing = showing + 1 | |
| 578 | |
| 579 if (not _this_row) then | |
| 580 | |
| 581 local name = button:GetName() .. "Row" .. i | |
| 582 local parent = scrollChild | |
| 583 | |
| 584 _this_row = CreateFrame ("Button", name, parent, "DetailsFrameworkDropDownOptionTemplate") | |
| 585 local anchor_i = i-1 | |
| 586 _this_row:SetPoint ("topleft", parent, "topleft", 5, (-anchor_i*20)-5) | |
| 587 _this_row:SetPoint ("topright", parent, "topright", -5, (-anchor_i*20)-5) | |
| 588 _this_row.object = object | |
| 589 object.menus [i] = _this_row | |
| 590 end | |
| 591 | |
| 592 _this_row.icon:SetTexture (_table.icon) | |
| 593 if (_table.icon) then | |
| 594 | |
| 595 _this_row.label:SetPoint ("left", _this_row.icon, "right", 5, 0) | |
| 596 | |
| 597 if (_table.texcoord) then | |
| 598 _this_row.icon:SetTexCoord (unpack (_table.texcoord)) | |
| 599 else | |
| 600 _this_row.icon:SetTexCoord (0, 1, 0, 1) | |
| 601 end | |
| 602 | |
| 603 if (_table.iconcolor) then | |
| 604 if (type (_table.iconcolor) == "string") then | |
| 605 _this_row.icon:SetVertexColor (DF:ParseColors (_table.iconcolor)) | |
| 606 else | |
| 607 _this_row.icon:SetVertexColor (unpack (_table.iconcolor)) | |
| 608 end | |
| 609 else | |
| 610 _this_row.icon:SetVertexColor (1, 1, 1, 1) | |
| 611 end | |
| 612 else | |
| 613 _this_row.label:SetPoint ("left", _this_row.statusbar, "left", 2, 0) | |
| 614 end | |
| 615 | |
| 616 if (_table.iconsize) then | |
| 617 _this_row.icon:SetSize (_table.iconsize[1], _table.iconsize[2]) | |
| 618 else | |
| 619 _this_row.icon:SetSize (20, 20) | |
| 620 end | |
| 621 | |
| 622 if (_table.font) then | |
| 623 _this_row.label:SetFont (_table.font, 10.5) | |
| 624 else | |
| 625 _this_row.label:SetFont ("GameFontHighlightSmall", 10.5) | |
| 626 end | |
| 627 | |
| 628 _this_row.statusbar:SetTexture (_table.statusbar) | |
| 629 _this_row.label:SetText (_table.label) | |
| 630 | |
| 631 if (currentText and currentText == _table.label) then | |
| 632 if (_table.icon) then | |
| 633 selectedTexture:SetPoint ("left", _this_row.icon, "left", -3, 0) | |
| 634 else | |
| 635 selectedTexture:SetPoint ("left", _this_row.statusbar, "left", 0, 0) | |
| 636 end | |
| 637 | |
| 638 selectedTexture:Show() | |
| 639 selectedTexture:SetVertexColor (1, 1, 1, .3); | |
| 640 currentText = nil | |
| 641 end | |
| 642 | |
| 643 if (_table.color) then | |
| 644 local _value1, _value2, _value3, _value4 = DF:ParseColors (_table.color) | |
| 645 _this_row.label:SetTextColor (_value1, _value2, _value3, _value4) | |
| 646 else | |
| 647 _this_row.label:SetTextColor (1, 1, 1, 1) | |
| 648 end | |
| 649 | |
| 650 _this_row.table = _table | |
| 651 | |
| 652 local labelwitdh = _this_row.label:GetStringWidth() | |
| 653 if (labelwitdh+40 > frame_witdh) then | |
| 654 frame_witdh = labelwitdh+40 | |
| 655 end | |
| 656 _this_row:Show() | |
| 657 | |
| 658 i = i + 1 | |
| 659 end | |
| 660 | |
| 661 end | |
| 662 | |
| 663 if (currentText) then | |
| 664 selectedTexture:Hide() | |
| 665 else | |
| 666 selectedTexture:SetWidth (frame_witdh-20) | |
| 667 end | |
| 668 | |
| 669 for i = showing+1, #object.menus do | |
| 670 object.menus [i]:Hide() | |
| 671 end | |
| 672 | |
| 673 local size = object.realsizeH | |
| 674 | |
| 675 if (showing*20 > size) then | |
| 676 --show scrollbar and setup scroll | |
| 677 object:ShowScroll() | |
| 678 scrollFrame:EnableMouseWheel (true) | |
| 679 object.scroll:Altura (size-35) | |
| 680 object.scroll:SetMinMaxValues (0, (showing*20) - size + 20) | |
| 681 --width | |
| 682 scrollBorder:SetWidth (frame_witdh+20) | |
| 683 scrollFrame:SetWidth (frame_witdh+20) | |
| 684 scrollChild:SetWidth (frame_witdh+20) | |
| 685 --height | |
| 686 scrollBorder:SetHeight (size+20) | |
| 687 scrollFrame:SetHeight (size) | |
| 688 scrollChild:SetHeight ((showing*20)+20) | |
| 689 --mouse over texture | |
| 690 mouseOverTexture:SetWidth (frame_witdh-7) | |
| 691 --selected | |
| 692 selectedTexture:SetWidth (frame_witdh - 9) | |
| 693 | |
| 694 for index, row in ipairs (object.menus) do | |
| 695 row:SetPoint ("topright", scrollChild, "topright", -22, ((-index-1)*20)-5) | |
| 696 end | |
| 697 | |
| 698 else | |
| 699 --hide scrollbar and disable wheel | |
| 700 object:HideScroll() | |
| 701 scrollFrame:EnableMouseWheel (false) | |
| 702 --width | |
| 703 scrollBorder:SetWidth (frame_witdh) | |
| 704 scrollFrame:SetWidth (frame_witdh) | |
| 705 scrollChild:SetWidth (frame_witdh) | |
| 706 --height | |
| 707 scrollBorder:SetHeight ((showing*20) + 25) | |
| 708 scrollFrame:SetHeight ((showing*20) + 25) | |
| 709 --mouse over texture | |
| 710 mouseOverTexture:SetWidth (frame_witdh-10) | |
| 711 --selected | |
| 712 selectedTexture:SetWidth (frame_witdh - 9) | |
| 713 | |
| 714 for index, row in ipairs (object.menus) do | |
| 715 row:SetPoint ("topright", scrollChild, "topright", -5, ((-index-1)*20)-5) | |
| 716 end | |
| 717 end | |
| 718 | |
| 719 object.scroll:SetValue (0) | |
| 720 object:Open() | |
| 721 | |
| 722 else | |
| 723 --> clear menu | |
| 724 | |
| 725 end | |
| 726 | |
| 727 else --> click to close | |
| 728 | |
| 729 object:Close() | |
| 730 end | |
| 731 | |
| 732 end | |
| 733 | |
| 734 function DetailsFrameworkDropDownOnEnter (self) | |
| 735 | |
| 736 if (self.MyObject.OnEnterHook) then | |
| 737 local interrupt = self.MyObject.OnEnterHook (self) | |
| 738 if (interrupt) then | |
| 739 return | |
| 740 end | |
| 741 end | |
| 742 | |
| 743 if (self.MyObject.onenter_backdrop) then | |
| 744 self:SetBackdropColor (unpack (self.MyObject.onenter_backdrop)) | |
| 745 else | |
| 746 self:SetBackdropColor (.2, .2, .2, .2) | |
| 747 end | |
| 748 | |
| 749 self.arrowTexture2:Show() | |
| 750 | |
| 751 if (self.MyObject.have_tooltip) then | |
| 752 GameCooltip2:Reset() | |
| 753 GameCooltip2:SetType ("tooltip") | |
| 754 GameCooltip2:SetColor ("main", "transparent") | |
| 755 DF:CooltipPreset (2) | |
| 756 GameCooltip2:AddLine (self.MyObject.have_tooltip) | |
| 757 GameCooltip2:SetOwner (self) | |
| 758 GameCooltip2:ShowCooltip() | |
| 759 end | |
| 760 | |
| 761 local parent = self:GetParent().MyObject | |
| 762 if (parent and parent.type == "panel") then | |
| 763 if (parent.GradientEnabled) then | |
| 764 parent:RunGradient() | |
| 765 end | |
| 766 end | |
| 767 | |
| 768 end | |
| 769 | |
| 770 function DetailsFrameworkDropDownOnLeave (self) | |
| 771 if (self.MyObject.OnLeaveHook) then | |
| 772 local interrupt = self.MyObject.OnLeaveHook (self) | |
| 773 if (interrupt) then | |
| 774 return | |
| 775 end | |
| 776 end | |
| 777 | |
| 778 if (self.MyObject.onleave_backdrop) then | |
| 779 self:SetBackdropColor (unpack (self.MyObject.onleave_backdrop)) | |
| 780 else | |
| 781 self:SetBackdropColor (1, 1, 1, .5) | |
| 782 end | |
| 783 | |
| 784 self.arrowTexture2:Hide() | |
| 785 | |
| 786 if (self.MyObject.have_tooltip) then | |
| 787 GameCooltip2:ShowMe (false) | |
| 788 end | |
| 789 | |
| 790 local parent = self:GetParent().MyObject | |
| 791 if (parent and parent.type == "panel") then | |
| 792 if (parent.GradientEnabled) then | |
| 793 parent:RunGradient (false) | |
| 794 end | |
| 795 end | |
| 796 end | |
| 797 | |
| 798 function DetailsFrameworkDropDownOnSizeChanged (self, w, h) | |
| 799 self.MyObject.label:SetSize (self:GetWidth()-40, 10) | |
| 800 end | |
| 801 | |
| 802 function DetailsFrameworkDropDownOnShow (self) | |
| 803 if (self.MyObject and self.MyObject.OnShowHook) then | |
| 804 local interrupt = self.MyObject.OnShowHook (self) | |
| 805 if (interrupt) then | |
| 806 return | |
| 807 end | |
| 808 end | |
| 809 end | |
| 810 | |
| 811 function DetailsFrameworkDropDownOnHide (self) | |
| 812 if (self.MyObject and self.MyObject.OnHideHook) then | |
| 813 local interrupt = self.MyObject.OnHideHook (self) | |
| 814 if (interrupt) then | |
| 815 return | |
| 816 end | |
| 817 end | |
| 818 | |
| 819 self.MyObject:Close() | |
| 820 end | |
| 821 | |
| 822 | |
| 823 | |
| 824 ------------------------------------------------------------------------------------------------------------ | |
| 825 --> object constructor | |
| 826 | |
| 827 function DF:CreateDropDown (parent, func, default, w, h, member, name) | |
| 828 return DF:NewDropDown (parent, parent, name, member, w, h, func, default) | |
| 829 end | |
| 830 | |
| 831 function DF:NewDropDown (parent, container, name, member, w, h, func, default) | |
| 832 | |
| 833 if (not name) then | |
| 834 name = "DetailsFrameworkDropDownNumber" .. DF.DropDownCounter | |
| 835 DF.DropDownCounter = DF.DropDownCounter + 1 | |
| 836 | |
| 837 elseif (not parent) then | |
| 838 return nil | |
| 839 end | |
| 840 if (not container) then | |
| 841 container = parent | |
| 842 end | |
| 843 | |
| 844 if (name:find ("$parent")) then | |
| 845 name = name:gsub ("$parent", parent:GetName()) | |
| 846 end | |
| 847 | |
| 848 local DropDownObject = {type = "dropdown", dframework = true} | |
| 849 | |
| 850 if (member) then | |
| 851 parent [member] = DropDownObject | |
| 852 end | |
| 853 | |
| 854 if (parent.dframework) then | |
| 855 parent = parent.widget | |
| 856 end | |
| 857 if (container.dframework) then | |
| 858 container = container.widget | |
| 859 end | |
| 860 | |
| 861 if (default == nil) then | |
| 862 default = 1 | |
| 863 end | |
| 864 | |
| 865 --> default members: | |
| 866 --> hooks | |
| 867 DropDownObject.OnEnterHook = nil | |
| 868 DropDownObject.OnLeaveHook = nil | |
| 869 DropDownObject.OnHideHook = nil | |
| 870 DropDownObject.OnShowHook = nil | |
| 871 DropDownObject.OnMouseDownHook = nil | |
| 872 --> misc | |
| 873 DropDownObject.container = container | |
| 874 DropDownObject.have_tooltip = nil | |
| 875 | |
| 876 DropDownObject.dropdown = CreateFrame ("Button", name, parent, "DetailsFrameworkDropDownTemplate") | |
| 877 DropDownObject.widget = DropDownObject.dropdown | |
| 878 | |
| 879 DropDownObject.__it = {nil, nil} | |
| 880 --_G [name] = DropDownObject | |
| 881 | |
| 882 if (not APIDropDownFunctions) then | |
| 883 APIDropDownFunctions = true | |
| 884 local idx = getmetatable (DropDownObject.dropdown).__index | |
| 885 for funcName, funcAddress in pairs (idx) do | |
| 886 if (not DropDownMetaFunctions [funcName]) then | |
| 887 DropDownMetaFunctions [funcName] = function (object, ...) | |
| 888 local x = loadstring ( "return _G."..object.dropdown:GetName()..":"..funcName.."(...)") | |
| 889 return x (...) | |
| 890 end | |
| 891 end | |
| 892 end | |
| 893 end | |
| 894 | |
| 895 DropDownObject.dropdown.MyObject = DropDownObject | |
| 896 | |
| 897 DropDownObject.dropdown:SetWidth (w) | |
| 898 DropDownObject.dropdown:SetHeight (h) | |
| 899 | |
| 900 DropDownObject.func = func | |
| 901 DropDownObject.realsizeW = 150 | |
| 902 DropDownObject.realsizeH = 150 | |
| 903 DropDownObject.FixedValue = nil | |
| 904 DropDownObject.opened = false | |
| 905 DropDownObject.menus = {} | |
| 906 DropDownObject.myvalue = nil | |
| 907 | |
| 908 DropDownObject.label = _G [name .. "_Text"] | |
| 909 | |
| 910 DropDownObject.icon = _G [name .. "_IconTexture"] | |
| 911 DropDownObject.statusbar = _G [name .. "_StatusBarTexture"] | |
| 912 DropDownObject.select = _G [name .. "_SelectedTexture"] | |
| 913 | |
| 914 local scroll = _G [DropDownObject.dropdown:GetName() .. "_ScrollFrame"] | |
| 915 | |
| 916 DropDownObject.scroll = DF:NewScrollBar (scroll, _G [DropDownObject.dropdown:GetName() .. "_ScrollFrame".."_ScrollChild"], -25, -18) | |
| 917 | |
| 918 function DropDownObject:HideScroll() | |
| 919 scroll.baixo:Hide() | |
| 920 scroll.cima:Hide() | |
| 921 scroll.slider:Hide() | |
| 922 end | |
| 923 function DropDownObject:ShowScroll() | |
| 924 scroll.baixo:Show() | |
| 925 scroll.cima:Show() | |
| 926 scroll.slider:Show() | |
| 927 end | |
| 928 | |
| 929 --button_down_scripts (DropDownObject, scroll.slider, scroll.baixo) | |
| 930 | |
| 931 DropDownObject:HideScroll() | |
| 932 DropDownObject.label:SetSize (DropDownObject.dropdown:GetWidth()-40, 10) | |
| 933 | |
| 934 --> setup class | |
| 935 _setmetatable (DropDownObject, DropDownMetaFunctions) | |
| 936 | |
| 937 --> initialize first menu selected | |
| 938 | |
| 939 if (type (default) == "string") then | |
| 940 DropDownObject:Select (default) | |
| 941 | |
| 942 elseif (type (default) == "number") then | |
| 943 if (not DropDownObject:Select (default)) then | |
| 944 DropDownObject:Select (default, true) | |
| 945 end | |
| 946 end | |
| 947 | |
| 948 return DropDownObject | |
| 949 | |
| 950 end |
