WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   How could I make this code much neater? (https://www.wowinterface.com/forums/showthread.php?t=53139)

jeAz_ 02-23-16 03:18 AM

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?

zork 02-23-16 05:43 AM

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?

jeAz_ 02-23-16 08:35 AM

Quote:

Originally Posted by zork (Post 313160)
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 :p

zork 02-23-16 09:34 AM

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.

jeAz_ 02-23-16 03:03 PM

Quote:

Originally Posted by zork (Post 313165)
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!


All times are GMT -6. The time now is 01:29 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI