Thread Tools Display Modes
07-07-12, 01:32 PM   #1
Paopao001
A Fallenroot Satyr
 
Paopao001's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 20
Raid frame change depending on Specialization

I wanted create two raid frames.One for healers(1) and the other for dps/tank(2).

Differences:
Size
Position
Indicators are only shown on the first one.
Aura icon size
Unit name's position on it's owner
Anchor-point, column Anchor-point(healer:5*5 dps/tank:1*25)

When I switch my spec, I want the raid frame to change with it. (without reload UI)

I've tried to use only one raid frame at first.But if I use oUF:SpawnHeader to a already 'spawned' one, there would be a lua error.However,I didn't know how to apply changes in other way.
Later I created two raid frames, I found the key is to hide one and show the other.I can't find a direct way to hide the raid frame. I finally came up with things below after lots of trial and error.

I did it, but I think my code probably is not the best solution.
I even doubt it may has some unknown side effects.
Anyone knows an easier way to do this?

Here's my code and add-on.
Lua Code:
  1. local ADDON_NAME, ns = ...
  2. local cfg = ns.cfg
  3. local oUF = ns.oUF or oUF
  4.  
  5. if not cfg.enableraid then return end
  6.  
  7. local mediaPath = cfg.mediaPath
  8. local texture = cfg.texture
  9. local glowTex = cfg.glowTex
  10. local font, fontsize = cfg.font, cfg.raidfontsize
  11. local myclass = select(2, UnitClass("player"))
  12. local Role
  13.  
  14. CheckRole = function()
  15.     local role
  16.     local tree = GetSpecialization()
  17.     if ((myclass == "MONK" and tree == 2) or (myclass == "PRIEST" and (tree == 1 or tree ==2)) or (myclass == "PALADIN" and tree == 1)) or (myclass == "DRUID" and tree == 3) or (myclass == "SHAMAN" and tree == 3) then
  18.         role = "Healer"
  19.     end
  20.     return role
  21. end
  22.  
  23. local func = function(self, unit)
  24.  
  25.     self:SetScript("OnEnter", UnitFrame_OnEnter)
  26.     self:SetScript("OnLeave", UnitFrame_OnLeave)
  27.  
  28.     self:RegisterForClicks"AnyUp"
  29.    
  30.     -- shadow border for health bar --
  31.     ns.backdrop(self, self, 0, 3)
  32.  
  33.     local hp = CreateFrame("StatusBar", nil, self)
  34.     hp:SetAllPoints(self)
  35.     hp:SetStatusBarTexture(texture)
  36.    
  37.     hp.frequentUpdates = true
  38.     hp.Smooth = true
  39.     if cfg.smoothhealthcolor then
  40.         self.colors.smooth = {1,0,0, 1,1,0, 1,1,0}
  41.         hp.colorSmooth = true
  42.     else
  43.         hp.colorClass = true
  44.         hp.colorReaction = true
  45.     end
  46.    
  47.     if not cfg.classcolormode then
  48.         hp:SetReverseFill(true)
  49.     end
  50.    
  51.     if not cfg.classcolormode then
  52.         hp:SetReverseFill(true)
  53.     end
  54.    
  55.     hp.PostUpdate = function(hp, unit, min, max)
  56.    
  57.         if not cfg.classcolormode then
  58.             if UnitIsDeadOrGhost(unit) then hp:SetValue(0)
  59.             else hp:SetValue(max - hp:GetValue()) end
  60.         end
  61.        
  62.         return ns.updatehealthcolor(hp:GetParent(), 'PostUpdateHealth', unit)
  63.     end
  64.    
  65.     self.Health = hp
  66.    
  67.     -- backdrop color --
  68.     local gradient = hp:CreateTexture(nil, "BACKGROUND")
  69.     gradient:SetPoint("TOPLEFT")
  70.     gradient:SetPoint("BOTTOMRIGHT")
  71.     gradient:SetTexture(cfg.texture)
  72.     gradient:SetGradientAlpha("VERTICAL", .3, .3, .3, .3, .1, .1, .1, .3)
  73.    
  74.     self.gradient = gradient
  75.    
  76.     local info = hp:CreateFontString(nil, "OVERLAY")
  77.     info:SetPoint("TOP")
  78.     info:SetFont(font, fontsize-3, "OUTLINE")
  79.     info:SetShadowOffset(0, 0)
  80.     info:SetTextColor(1, 1, 1)
  81.     self:Tag(info, '[Mlight:raidinfo]')
  82.    
  83.     local raidname = hp:CreateFontString(nil, "OVERLAY")
  84.     raidname:SetPoint("BOTTOMRIGHT", hp, "BOTTOMRIGHT", -1, 5)
  85.  
  86.     raidname:SetFont(font, fontsize, "OUTLINE")
  87.     raidname:SetShadowOffset(0, 0)
  88.     if not cfg.classcolormode then
  89.         self:Tag(raidname, '[Mlight:color][Mlight:shortname]')
  90.     else
  91.         self:Tag(raidname, '[Mlight:shortname]')
  92.     end
  93.    
  94.     local ricon = hp:CreateTexture(nil, "OVERLAY")
  95.     ricon:SetPoint("BOTTOM", hp, "TOP", 0 , -5)
  96.     ricon:SetSize(10 ,10)
  97.     self.RaidIcon = ricon
  98.  
  99.     -- Auras
  100.     local auras = CreateFrame("Frame", nil, self)
  101.     auras:SetSize(16, 16)
  102.     auras:SetPoint("LEFT", hp, "LEFT", 5, 0)
  103.     auras.tfontsize = 13
  104.     auras.cfontsize = 8
  105.     self.MlightAuras = auras
  106.    
  107.  
  108.     -- Indicators
  109.     self.MlightIndicators = true
  110.    
  111.     -- Range
  112.     local range = {
  113.         insideAlpha = 1,
  114.         outsideAlpha = 0.5,
  115.     }
  116.     self.Range = range
  117.    
  118. end
  119.  
  120. local dfunc = function(self, unit)
  121.  
  122.     self:SetScript("OnEnter", UnitFrame_OnEnter)
  123.     self:SetScript("OnLeave", UnitFrame_OnLeave)
  124.  
  125.     self:RegisterForClicks"AnyUp"
  126.    
  127.     -- shadow border for health bar --
  128.     ns.backdrop(self, self, 0, 3)
  129.  
  130.     local hp = CreateFrame("StatusBar", nil, self)
  131.     hp:SetAllPoints(self)
  132.     hp:SetStatusBarTexture(texture)
  133.    
  134.     hp.frequentUpdates = true
  135.     hp.Smooth = true
  136.     if cfg.smoothhealthcolor then
  137.         self.colors.smooth = {1,0,0, 1,1,0, 1,1,0}
  138.         hp.colorSmooth = true
  139.     else
  140.         hp.colorClass = true
  141.         hp.colorReaction = true
  142.     end
  143.    
  144.     if not cfg.classcolormode then
  145.         hp:SetReverseFill(true)
  146.     end
  147.    
  148.     if not cfg.classcolormode then
  149.         hp:SetReverseFill(true)
  150.     end
  151.    
  152.     hp.PostUpdate = function(hp, unit, min, max)
  153.    
  154.         if not cfg.classcolormode then
  155.             if UnitIsDeadOrGhost(unit) then hp:SetValue(0)
  156.             else hp:SetValue(max - hp:GetValue()) end
  157.         end
  158.        
  159.         return ns.updatehealthcolor(hp:GetParent(), 'PostUpdateHealth', unit)
  160.     end
  161.    
  162.     self.Health = hp
  163.    
  164.     -- backdrop color --
  165.     local gradient = hp:CreateTexture(nil, "BACKGROUND")
  166.     gradient:SetPoint("TOPLEFT")
  167.     gradient:SetPoint("BOTTOMRIGHT")
  168.     gradient:SetTexture(cfg.texture)
  169.     gradient:SetGradientAlpha("VERTICAL", .3, .3, .3, .3, .1, .1, .1, .3)
  170.    
  171.     self.gradient = gradient
  172.    
  173.     local info = hp:CreateFontString(nil, "OVERLAY")
  174.     info:SetPoint("TOP")
  175.     info:SetFont(font, fontsize-3, "OUTLINE")
  176.     info:SetShadowOffset(0, 0)
  177.     info:SetTextColor(1, 1, 1)
  178.     self:Tag(info, '[Mlight:raidinfo]')
  179.    
  180.     local raidname = hp:CreateFontString(nil, "OVERLAY")
  181.     raidname:SetPoint("BOTTOMLEFT", hp, "BOTTOMRIGHT", 5, 0)
  182.  
  183.     raidname:SetFont(font, fontsize, "OUTLINE")
  184.     raidname:SetShadowOffset(0, 0)
  185.     if not cfg.classcolormode then
  186.         self:Tag(raidname, '[Mlight:color][Mlight:shortname]')
  187.     else
  188.         self:Tag(raidname, '[Mlight:shortname]')
  189.     end
  190.    
  191.     local ricon = hp:CreateTexture(nil, "OVERLAY")
  192.     ricon:SetPoint("BOTTOM", hp, "TOP", 0 , -5)
  193.     ricon:SetSize(10 ,10)
  194.     self.RaidIcon = ricon
  195.  
  196.     -- Auras
  197.     local auras = CreateFrame("Frame", nil, self)
  198.     auras:SetSize(10, 10)
  199.     auras:SetPoint("LEFT", hp, "LEFT", 5, 0)
  200.     auras.tfontsize = 1
  201.     auras.cfontsize = 1
  202.     self.MlightAuras = auras
  203.    
  204.     -- Range
  205.     local range = {
  206.         insideAlpha = 1,
  207.         outsideAlpha = 0.5,
  208.     }
  209.     self.Range = range
  210.    
  211. end
  212.  
  213. oUF:RegisterStyle("Mlight_Healerraid", func)
  214. oUF:RegisterStyle("Mlight_DPSraid", dfunc)
  215.  
  216. local healerraid, dpsraid
  217.  
  218. oUF:SetActiveStyle"Mlight_Healerraid"
  219. healerraid = oUF:SpawnHeader('HealerRaid_Mlight', nil, 'raid,party,solo',
  220. 'oUF-initialConfigFunction', ([[
  221. self:SetWidth(%d)
  222. self:SetHeight(%d)
  223. self:SetScale(%d)
  224. ]]):format(cfg.healerraidwidth, cfg.healerraidheight, 1),
  225. 'showPlayer', true,
  226. 'showSolo', cfg.showsolo,
  227. 'showParty', true,
  228. 'showRaid', true,
  229. 'xoffset', 5,
  230. 'yOffset', -5,
  231. 'point', "LEFT",
  232. 'groupFilter', '1,2,3,4,5,6,7,8',
  233. 'groupingOrder', '1,2,3,4,5,6,7,8',
  234. 'groupBy', 'GROUP',
  235. 'maxColumns', 5,
  236. 'unitsPerColumn', 5,
  237. 'columnSpacing', 5,
  238. 'columnAnchorPoint', "TOP"
  239. )
  240. healerraid:SetPoint(unpack(cfg.healerraidposition))
  241.  
  242. oUF:SetActiveStyle"Mlight_DPSraid"
  243. dpsraid = oUF:SpawnHeader('DpsRaid_Mlight', nil, 'raid,party,solo',
  244. 'oUF-initialConfigFunction', ([[
  245. self:SetWidth(%d)
  246. self:SetHeight(%d)
  247. self:SetScale(%d)
  248. ]]):format(cfg.dpsraidwidth, cfg.dpsraidheight, 1),
  249. 'showPlayer', true,
  250. 'showSolo', cfg.showsolo,
  251. 'showParty', true,
  252. 'showRaid', true,
  253. 'xoffset', 5,
  254. 'yOffset', -5,
  255. 'point', "TOP",
  256. 'groupFilter', '1,2,3,4,5,6,7,8',
  257. 'groupingOrder', '1,2,3,4,5,6,7,8',
  258. 'groupBy', 'GROUP',
  259. 'maxColumns', 5,
  260. 'unitsPerColumn', 5,
  261. 'columnSpacing', 5,
  262. 'columnAnchorPoint', "TOP"
  263. )
  264. dpsraid:SetPoint(unpack(cfg.dpsraidposition))
  265.  
  266. function hiderf(f)
  267.     show = f.Show
  268.     f:Hide()
  269.     f.Show = f.Hide
  270.     f.show = show
  271.     f.mode = 0
  272. end
  273.  
  274. function showrf(f)
  275.     f.Show = f.show
  276.     f:Show()
  277.     f.mode = 1
  278. end
  279.  
  280. hiderf(healerraid)
  281. hiderf(dpsraid)
  282.  
  283. local RoleUpdater = CreateFrame("Frame")
  284. function RoleUpdater:togglerf()
  285.     Role = CheckRole()
  286.     if Role then
  287.         if dpsraid.mode == 1 then hiderf(dpsraid) end
  288.         if healerraid.mode == 0 then showrf(healerraid) end
  289.     else
  290.         if healerraid.mode == 1 then hiderf(healerraid) end
  291.         if dpsraid.mode == 0 then showrf(dpsraid) end
  292.     end
  293. end
  294.  
  295. RoleUpdater:RegisterEvent("PLAYER_ENTERING_WORLD")
  296. RoleUpdater:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
  297. RoleUpdater:RegisterEvent("PLAYER_TALENT_UPDATE")
  298. RoleUpdater:RegisterEvent("CHARACTER_POINTS_CHANGED")
  299. RoleUpdater:RegisterEvent("UNIT_INVENTORY_CHANGED")
  300. RoleUpdater:RegisterEvent("UPDATE_BONUS_ACTIONBAR")
  301.  
  302. RoleUpdater:SetScript("OnEvent", RoleUpdater.togglerf)
  Reply With Quote
07-07-12, 01:49 PM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
There is a macro conditional for specs.

You could have 2 raidframes and add a macro condition via RegisterStateDriver to each of them.

Lua Code:
  1. --frame1
  2. local frame1 = CreateFrame("FRAME","MyRaidDragFrameForDPS",UIParent, "SecureHandlerStateTemplate")
  3. RegisterStateDriver(frame1, "visibility", "[spec:1] show;hide")
  4. --frame2
  5. local frame2 = CreateFrame("FRAME","MyRaidDragFrameForHEAL",UIParent, "SecureHandlerStateTemplate")
  6. RegisterStateDriver(frame2, "visibility", "[spec:2] show;hide")


But I'm not sure if that is will kill all the performance heavy events in the background. Since the frame that all the headers should be anchored to is hidden it should work out.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 07-07-12 at 01:52 PM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Raid frame change depending on Specialization


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off