comparison classes/ReBar.lua @ 8:c05fd3e18b4f

Version 0.31
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:33:59 +0000
parents f920db5fc6b1
children f3a7bfebc283
comparison
equal deleted inserted replaced
7:f920db5fc6b1 8:c05fd3e18b4f
147 error("ReBar: Supplied Button type does not meet required interface.") 147 error("ReBar: Supplied Button type does not meet required interface.")
148 end 148 end
149 149
150 150
151 -- create the bar and control widgets 151 -- create the bar and control widgets
152 self.barFrame = CreateFrame("Frame", "ReBar"..id, config.parent and getglobal(config.parent) or UIParent, "ReBarTemplate") 152 local name = "ReBar"..id
153 self.barFrame = CreateFrame("Frame", name, config.parent and getglobal(config.parent) or UIParent, "ReBarTemplate")
153 self.controlFrame = getglobal(self.barFrame:GetName().."Controls") 154 self.controlFrame = getglobal(self.barFrame:GetName().."Controls")
154 self.controlFrame.reBar = self 155 self.controlFrame.reBar = self
155 self.barFrame:SetClampedToScreen(true) 156 self.barFrame:SetClampedToScreen(true)
156 157
158 -- get references to sub-frames
159 self.labelString = getglobal(name.."ControlsLabelString")
160 self.upArrow = getglobal(name.."PageUp")
161 self.downArrow = getglobal(name.."PageDown")
162 self.pageNum = getglobal(name.."PageNumber")
163
157 -- set the text label on the control widget 164 -- set the text label on the control widget
158 self.labelString = getglobal(self.controlFrame:GetName().."LabelString")
159 self.labelString:SetText(id) 165 self.labelString:SetText(id)
160 166
161 -- initial stateheader state 167 -- initial stateheader state
162 self.barFrame.StateChanged = function() self:StateChanged() end 168 self.barFrame.StateChanged = function() self:StateChanged() end
163 self.barFrame:SetAttribute("state",config.pages and config.pages.currentPage or 1) -- initial state 169 self.barFrame:SetAttribute("state",config.pages and config.pages.currentPage or 1) -- initial state
176 self:RefreshPageControls() 182 self:RefreshPageControls()
177 end 183 end
178 184
179 -- register page up/down buttons with ReBound for keybinding 185 -- register page up/down buttons with ReBound for keybinding
180 if ReBound then 186 if ReBound then
181 ReBound:AddKeybindTarget(getglobal(self.barFrame:GetName().."PageUp")) 187 ReBound:AddKeybindTarget(self.upArrow)
182 ReBound:AddKeybindTarget(getglobal(self.barFrame:GetName().."PageDown")) 188 ReBound:AddKeybindTarget(self.downArrow)
183 end 189 end
184 190
185 -- add bar to anchorTargets list 191 -- add bar to anchorTargets list
186 table.insert(ReBar.anchorTargets, self) 192 table.insert(ReBar.anchorTargets, self)
187 end 193 end
279 function ReBar.prototype:SetVisibility(v) 285 function ReBar.prototype:SetVisibility(v)
280 self.config.visible = v and true or false -- force data integrity 286 self.config.visible = v and true or false -- force data integrity
281 self:ApplyVisibility() 287 self:ApplyVisibility()
282 end 288 end
283 289
284 function ReBar.prototype:GetOpacity()
285 return tonumber(self.config.opacity) or 100
286 end
287
288 function ReBar.prototype:SetOpacity( o )
289 o = tonumber(o)
290 if o then
291 self.config.opacity = o
292 self:ApplyVisibility()
293 return self.config.opacity
294 end
295 end
296
297 function ReBar.prototype:GetButtonList() 290 function ReBar.prototype:GetButtonList()
298 return self.buttons 291 return self.buttons
299 end 292 end
300 293
301 function ReBar.prototype:GetGrowLeft() 294 function ReBar.prototype:GetGrowLeft()
376 self:SetAutoStanceSwitch( not self:GetAutoStanceSwitch() ) 369 self:SetAutoStanceSwitch( not self:GetAutoStanceSwitch() )
377 end 370 end
378 371
379 function ReBar.prototype:ApplyAutoStanceSwitch() 372 function ReBar.prototype:ApplyAutoStanceSwitch()
380 local switch = self:GetAutoStanceSwitch() 373 local switch = self:GetAutoStanceSwitch()
381 local _, class = UnitClass("player")
382 if switch then 374 if switch then
383 -- check that the number of pages available is sufficient 375 -- check that the number of pages available is sufficient
384 local totalPages = nStancePages[class] + (self:GetAutoStealthSwitch() and 1 or 0) 376 local totalPages = nStancePages[playerClass] + (self:GetAutoStealthSwitch() and 1 or 0)
385 if self:GetPages() < totalPages then 377 if self:GetPages() < totalPages then
386 self:SetPages(totalPages) 378 self:SetPages(totalPages)
387 end 379 end
388 for form, spec in pairs(stanceMaps[class]) do 380 for form, spec in pairs(stanceMaps[playerClass]) do
389 self.barFrame:SetAttribute("statemap-stance-"..form,spec) 381 self.barFrame:SetAttribute("statemap-stance-"..form,spec)
390 end 382 end
391 -- set initial value 383 -- set initial value
392 self.barFrame:SetAttribute("state-stance",GetShapeshiftForm(true)) 384 self.barFrame:SetAttribute("state-stance",GetShapeshiftForm(true))
393 else 385 else
394 for form, _ in pairs(stanceMaps[class]) do 386 for form, _ in pairs(stanceMaps[playerClass]) do
395 self.barFrame:SetAttribute("statemap-stance-"..form, ATTRIBUTE_NOOP) 387 self.barFrame:SetAttribute("statemap-stance-"..form, ATTRIBUTE_NOOP)
396 end 388 end
397 end 389 end
398 end 390 end
399 391
413 self:SetAutoStealthSwitch( not self:GetAutoStealthSwitch() ) 405 self:SetAutoStealthSwitch( not self:GetAutoStealthSwitch() )
414 end 406 end
415 407
416 function ReBar.prototype:ApplyAutoStealthSwitch() 408 function ReBar.prototype:ApplyAutoStealthSwitch()
417 local switch = self:GetAutoStealthSwitch() 409 local switch = self:GetAutoStealthSwitch()
418 local _, class = UnitClass("player")
419 if switch then 410 if switch then
420 -- check that the number of pages available is sufficient 411 -- check that the number of pages available is sufficient
421 local totalPages = (self:GetAutoStanceSwitch() and nStancePages[class] > 0 and nStancePages[class] or 1) + 1 412 local totalPages = (self:GetAutoStanceSwitch() and nStancePages[playerClass] > 0 and nStancePages[playerClass] or 1) + 1
422 if self:GetPages() < totalPages then 413 if self:GetPages() < totalPages then
423 self:SetPages(totalPages) 414 self:SetPages(totalPages)
424 end 415 end
425 local s, s2 416 local s, s2
426 if class == "DRUID" and not self:GetAutoStanceSwitch() then 417 if playerClass == "DRUID" and not self:GetAutoStanceSwitch() then
427 -- change mapping for cat->prowl and prowl->cat to 1:2 and 2:1 since no stance mapping 418 -- change mapping for cat->prowl and prowl->cat to 1:2 and 2:1 since no stance mapping
428 s = "1:2" 419 s = "1:2"
429 s2 = "2:1" 420 s2 = "2:1"
430 end 421 end
431 self.barFrame:SetAttribute("statemap-stealth-1",s or stealthMaps[class]) 422 self.barFrame:SetAttribute("statemap-stealth-1",s or stealthMaps[playerClass])
432 self.barFrame:SetAttribute("statemap-stealth-0",s2 or unstealthMaps[class]) 423 self.barFrame:SetAttribute("statemap-stealth-0",s2 or unstealthMaps[playerClass])
433 -- set initial value 424 -- set initial value
434 self.barFrame:SetAttribute("state-stealth",IsStealthed() or 0) 425 self.barFrame:SetAttribute("state-stealth",IsStealthed() or 0)
435 else 426 else
436 self.barFrame:SetAttribute("statemap-stealth-1",ATTRIBUTE_NOOP) 427 self.barFrame:SetAttribute("statemap-stealth-1",ATTRIBUTE_NOOP)
437 self.barFrame:SetAttribute("statemap-stealth-0",ATTRIBUTE_NOOP) 428 self.barFrame:SetAttribute("statemap-stealth-0",ATTRIBUTE_NOOP)
460 end 451 end
461 end 452 end
462 453
463 function ReBar.prototype:RefreshPageControls() 454 function ReBar.prototype:RefreshPageControls()
464 local b = self.barFrame; 455 local b = self.barFrame;
465 local upArrow = getglobal(b:GetName().."PageUp") 456 local upArrow = self.upArrow
466 local downArrow = getglobal(b:GetName().."PageDown") 457 local downArrow = self.downArrow
467 local pageNum = getglobal(b:GetName().."PageNumber") 458 local pageNum = self.pageNum
468 459
469 if self:GetPages() > 1 and self.config.pages.showControls then 460 if self:GetPages() > 1 and self.config.pages.showControls then
470 local loc = self.config.pages.controlsLoc 461 local loc = self.config.pages.controlsLoc
462
463 upArrow:SetAttribute("hidestates",nil)
464 downArrow:SetAttribute("hidestates",nil)
471 465
472 pageNum:ClearAllPoints() 466 pageNum:ClearAllPoints()
473 upArrow:ClearAllPoints() 467 upArrow:ClearAllPoints()
474 downArrow:ClearAllPoints() 468 downArrow:ClearAllPoints()
475 469
517 self:StateChanged() 511 self:StateChanged()
518 upArrow:Show() 512 upArrow:Show()
519 downArrow:Show() 513 downArrow:Show()
520 pageNum:Show() 514 pageNum:Show()
521 else 515 else
516 upArrow:SetAttribute("hidestates","1-"..self:GetPages())
517 downArrow:SetAttribute("hidestates","1-"..self:GetPages())
518
522 upArrow:Hide() 519 upArrow:Hide()
523 downArrow:Hide() 520 downArrow:Hide()
524 pageNum:Hide() 521 pageNum:Hide()
525 end 522 end
526 end 523 end
564 end 561 end
565 562
566 function ReBar.prototype:ApplyVisibility() 563 function ReBar.prototype:ApplyVisibility()
567 local v = self.config.visible or not self.locked 564 local v = self.config.visible or not self.locked
568 565
569 if tonumber(self.config.opacity) then
570 self.barFrame:SetAlpha(self.config.opacity / 100)
571 end
572
573 if v then 566 if v then
574 self.barFrame:Show() 567 self.barFrame:Show()
575 else 568 else
576 self.barFrame:Hide() 569 self.barFrame:Hide()
577 end 570 end
829 function ReBar.prototype:ShowBarResizeTooltip(point) 822 function ReBar.prototype:ShowBarResizeTooltip(point)
830 GameTooltip:SetOwner(self.barFrame, "ANCHOR_"..point) 823 GameTooltip:SetOwner(self.barFrame, "ANCHOR_"..point)
831 GameTooltip:AddLine("Drag to add/remove buttons") 824 GameTooltip:AddLine("Drag to add/remove buttons")
832 GameTooltip:Show() 825 GameTooltip:Show()
833 end 826 end
827