Thread Tools Display Modes
02-23-16, 03:18 AM   #1
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
How could I make this code much neater?

So, I currently have the following code written.

Lua Code:
  1. A.CreateDruidMana = function(f, unit)
  2.  local DruidMana = CreateFrame("StatusBar", "DruidMana", f);
  3.  DruidMana:SetStatusBarTexture(POWER_BAR);
  4.  DruidMana:SetOrientation("VERTICAL");
  5.  
  6.  DruidMana.background = DruidMana:CreateTexture(nil, "BACKGROUND");
  7.  DruidMana.background:SetTexture(BACKDROP);
  8.  DruidMana.background:SetVertexColor(0.1, 0.1, 0.1, 1);
  9.  DruidMana.background:SetSize(10, f:GetHeight());
  10.  DruidMana.background:SetPoint("LEFT", f, "RIGHT", 2, 0);
  11.  
  12.  DruidMana:SetPoint("TOPLEFT", DruidMana.background, "TOPLEFT", 2, -2);
  13.  DruidMana:SetPoint("BOTTOMRIGHT", DruidMana.background, "BOTTOMRIGHT", -2, 2);
  14.  
  15.  local bg = DruidMana:CreateTexture(nil, "BACKGROUND");
  16.  bg:SetAllPoints(true);
  17.  bg:SetTexture(BACKDROP);
  18.  
  19.  A.AddOptions(DruidMana, "frequentUpdates");
  20.  bg.multiplier = 0.2;
  21.  
  22.  f.DruidMana = DruidMana;
  23.  f.DruidMana.bg = bg;
  24. end

The reason that I created another texture called Background is to create a outer background like the following image:



However, I would like to Create "DruidMana" as a "Frame" rather than "StatusBar" and create "StatusBar" called "Bar" which becomes child object of "DruidMana" then Set Backdrop for "DruidMana" which I would like to use as outer frame instead of using texture called "Background".

Which would become:

Lua Code:
  1. local DruidMana = CreateFrame("Frame", "DruidMana", f);
  2. local Bar = CreateFrame("StatusBar", nil, DruidMana);
  3. local bg = Bar:CreateTexture(nil, "BACKGROUND");

I actually tried it, but it was not possible to set "DruidMana" as "f.DruidMana" since "DruidMana" was set to "Frame", not "StatusBar".

In addition to that even if I set "Bar" as "f.DruidMana", "DruidMana" does not hide on shape shift...

Could I please get an advice regarding this?
  Reply With Quote
02-23-16, 05:43 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Why don't you just create a frame for the backdrop and give it a framelevel below the statusbar?

Lua Code:
  1. local background = CreateFrame("Frame",nil,bar)
  2. background:SetBackdrop(backdrop)
  3. brackground:SetFrameLevel(bar:GetFrameLevel()-1)

Additionally. I'm a bit rusty but can't you just add the backdrop to the statusbar?
__________________
| 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 : 02-23-16 at 05:46 AM.
  Reply With Quote
02-23-16, 08:35 AM   #3
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
Originally Posted by zork View Post
Why don't you just create a frame for the backdrop and give it a framelevel below the statusbar?

Lua Code:
  1. local background = CreateFrame("Frame",nil,bar)
  2. background:SetBackdrop(backdrop)
  3. brackground:SetFrameLevel(bar:GetFrameLevel()-1)

Additionally. I'm a bit rusty but can't you just add the backdrop to the statusbar?
API says that you can definitely add backdrop to statusbar as well and I've actually tried that, but I don't know. Maybe I've just misused it.

Could you please provide me with an example, if you don't mind
  Reply With Quote
02-23-16, 09:34 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I checked one of my outdated addons. I sort of did what you are looking for. I used a helper frame to work around issues with backdrop insets.
https://github.com/zorker/rothui/blo.../core.lua#L118
http://www.wowinterface.com/download...UF_Simple.html
Be aware that the example is for an outdated version of oUF but the statusbar and backdrops have not changed.
__________________
| 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 : 02-23-16 at 09:36 AM.
  Reply With Quote
02-23-16, 03:03 PM   #5
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
Originally Posted by zork View Post
I checked one of my outdated addons. I sort of did what you are looking for. I used a helper frame to work around issues with backdrop insets.
https://github.com/zorker/rothui/blo.../core.lua#L118
http://www.wowinterface.com/download...UF_Simple.html
Be aware that the example is for an outdated version of oUF but the statusbar and backdrops have not changed.
It worked well

Thank you for your help!
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » How could I make this code much neater?

Thread Tools
Display Modes

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