WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Where to start? - Boilerplate Help (https://www.wowinterface.com/forums/showthread.php?t=56007)

Jagwah 01-28-18 01:27 PM

Where to start? - Boilerplate Help
 
Hi all,

I'll preface this by admitting that I'm very new to all of this; outside of editing the lua of existing addons, I don't have much experience and I'm pretty much learning as I go.

My first question is about documentation--I've not found much other than the in-line documentation in the oUF code and the boilerplate. Does anything along these lines exist?

I've had a go at spawning a player health bar; it's not throwing up any errors but isn't displaying either. I feel like I might have missed something really obvious, but after an hour of checking various bits I just can't work it out. Can anyone point me in the right direction?

EDIT: Having tested, my party frames have disappeared too.

Thanks in advance! I have oUF where it should be (unembedded) and have a single TOC entry pointing to a single LUA file (which I've pasted in its entirety below):

Lua Code:
  1. local _, ns = ...
  2.  
  3. local UnitSpecific = {
  4.   player = function(self) -- Player Specific Code
  5.   end,
  6.  
  7.   party = function(self)  -- Party Specific Code
  8.   end,
  9. }
  10.  
  11.  
  12. local Shared = function(self, unit) -- Shared Unit Code
  13.  
  14.   local Health = CreateFrame('StatusBar', nil, self) -- Create Health Bar
  15.   Health:SetSize(300, 20)
  16.   Health:SetPoint('TOPLEFT', UIParent, "TOPRIGHT", 0, 0)
  17.   Health:SetPoint('BOTTOMLEFT', UIParent, "BOTTOMRIGHT", 0, 0)
  18.  
  19.   local HealthBG = Health:CreateTexture(nil, 'BACKGROUND') -- Create Health Background
  20.   HealthBG:SetAllPoints(Health)
  21.   HealthBG:SetTexture(1, 1, 1, .5)
  22.  
  23.   Health.colorClass = true
  24.   Health.colorReaction = true
  25.  
  26.   HealthBG.multiplier = .5
  27.  
  28.   Health.bg = HealthBG
  29.   self.Health = Health
  30.  
  31.  
  32.   if(UnitSpecific[unit]) then
  33.       return UnitSpecific[unit](self)
  34.     end
  35.   end
  36.  
  37.  
  38. oUF:RegisterStyle("jUI", Shared) --Register Style with oUF
  39. oUF:Factory(function(self)
  40.  
  41.   self:SetActiveStyle("jUI")
  42.   self:Spawn("player"):SetPoint('CENTER')
  43.  
  44.   local party = self:SpawnHeader(nil, nil, 'raid,party,solo',
  45.     'showParty', true,
  46.     'showPlayer', true,
  47.     'yOffset', -20
  48.     )
  49.   party:SetPoint("TOPLEFT", 30, -30)
  50. end)

zork 01-28-18 02:07 PM

Here is a super simple layout to get you started.
https://github.com/zorker/rothui/blo...iler/spawn.lua

Personally I have not used the factory yet.
Spawning any unit other than party and raid is pretty straight forward. Those need a group header and some more config settings.

Jagwah 01-28-18 03:20 PM

Thanks Zork (big fan!), this is exactly what I was looking for.

Would you mind briefly explaining how oUF Factory works? As I understand it, it's just a pre-built frame that you can edit, rather than spawning your own--is that right?

zork 01-28-18 04:42 PM

You can check p3lims layout.
https://github.com/p3lim-wow/oUF_P3l...P3lim.lua#L610

The factory allows you to register a function that runs on PLAYER_LOGIN which normally activates a style function and spawns all the units you have specified.
p3lim is using one style function for all called Shared but in that style function he has a conditional check for unitspecific. If it matches another subset function will be called for unitspecific settings.

My approach is a little different. I like to have seperate style functions per unit that load a unit specific config and then call a generic style function which is creating all desired elements based on config settings. On top of that I spawn the units directly when the addon is loaded and not on player login.

You would need to do the latter if you have saved variables which load after the addon is executed and before the player is logged in.

You can easily use the factory with my example by enclosing the spawn in a function which you call with the factory.
https://github.com/zorker/rothui/com...c338fbdc454150

Jagwah 01-28-18 05:36 PM

Useful, thank you.

I think that what I'm failing to understand is what oUF Factory actually does.

What purpose does it serve? Like I say, I'm a total beginner.

zork 01-28-18 05:51 PM

If the player is logged in the function provided to the factory is called immediately. If not it is called once the event PLAYER_LOGIN has fired.

https://github.com/oUF-wow/oUF/blob/...actory.lua#L27

Jagwah 01-28-18 05:53 PM

Gotcha. Thanks for your help man. :)

I'm sure I'll be back in the future with some more questions!

Rainrider 02-02-18 11:36 AM

Quote:

Originally Posted by zork (Post 326674)
Here is a super simple layout to get you started.
https://github.com/zorker/rothui/blo...iler/spawn.lua

Personally I have not used the factory yet.
Spawning any unit other than party and raid is pretty straight forward. Those need a group header and some more config settings.

You are using the factory: https://github.com/zorker/rothui/blo...spawn.lua#L194

@Jagwah
You pass a callback to the factory, that is a function which specifies which styles are to be used for which units, and creates (spawns) and places the unit frames. You can call the factory multiple times. Callbacks are then executed in the call order, thus you control this order for your layout. So basically a callback suitable for oUF's factory is a function consisting of calls to oUF:SetActiveStyle, oUF:Spawn/oUF:SpawnHeader and frame:SetPoint. oUF is passed as an argument to your callback and frame is the return of :Spawn/:SpawnHeader

A style in oUF terms is a tuple consisting of a style name and a style function. The name has to be unique, so using your layout name as a prefix is a good idea. The style function defines the visual appearance of the unit frames spawned in the factory callback after :SetActiveStyle has been called with the specified style name. Your styles have to be known to oUF, so you have to use oUF:RegisterStyle(styleName, styleFunction) before you call oUF's factory.

How and where you define your style function is entirely up to you. Normally you would strive to do some separation by domain and by concern and reduce code repetition. This will make your code easier to read and follow and thus easier to maintain. A good idea is to define different styles for different units based on their appearance, e.g. player and target are normally the most prominent frames in a layout, so group them together in one style. Pet, focus and targettarget could share a separate style as well, the same for party and raid. You could then easily test different styles by just changing the argument in the :SetActiveStyle call.

zork 02-02-18 04:42 PM

I'm really not sure what to say...

Jagwah 02-06-18 07:51 AM

Thanks Rainrider, that puts it in really simple terms.

I'm not sure what you mean, Zork? I've had a busy few weeks but got some time to sit down with your boiler layout this evening. Reading over all of this has made me realise that I probably need to revise the basics before I can make sense of everything, but this is more than enough to get started.

One more question, and I appreciate that I've asked a lot already--how would spawning nameplates work in your way of doing things? The demo in the sticky uses unit:match("nameplate") as part of an if statement, but I can't see any way to check for that in your example.

Would you create a separate config entry for L.C.nameplate, and then link that back to oUF using frame.health = XXXX? Or would it need to be handled totally separately as it isn't sharing the common style?

I'm not entirely sure I'm making sense, so don't worry too much if I'm way off the mark. Still a lot to learn!

Thanks, both, for your help.

zork 02-06-18 11:30 AM

That was just regarding Rainriders quote. By the time of posting I had not used the Factory. I added two posts later and linked the commit.

Nameplates are easy to spawn too.
https://github.com/zorker/rothui/blo...spawn.lua#L148
https://github.com/oUF-wow/oUF/blob/master/ouf.lua#L742

Jagwah 02-06-18 01:36 PM

Ah, right.

Thanks so much for your help, it's much appreciated. Plenty to be getting on with!

Jagwah 02-12-18 02:10 PM

Hello again -- I've had a play around with the boiler layout and after rewriting a few times to try and get the hang of it, I've managed to get a power bar loaded too.

The problem that I'm having is that despite setting different points in the settings table, the power bar is layering directly under the health bar, and I can't get it to move.

Here's my code: https://pastebin.com/y7wqPLiY

I'm sure there are more efficient ways to setup the power bar than directly duplicating the SetupFrame function, but this was the easiest way I could work it out!

Any ideas?

Eungavi 02-12-18 06:07 PM

To me, it seems like you are setting points of oUF object, not a power bar's.

Code:

local function SetupHealthFrame(self)
    if not self.settings.setupHealthFrame then return end
    self:SetSize(unpack(self.cfg.hsize))
    self:SetPoint(unpack(self.cfg.hpoint))
    self:SetScale(self.cfg.scale)
end
 
local function SetupPowerFrame(self)
    if not self.settings.setupPowerFrame then return end
    self:SetSize(unpack(self.cfg.psize))
    self:SetPoint(unpack(self.cfg.ppoint))
    self:SetScale(self.cfg.scale)
end

local function CreateStyle(self)
    SetupHealthFrame(self) ← passing oUF object
    SetupPowerFrame(self) ← passing oUF object
    SetupEvents(self)
    self.Health = CreateHealthBar(self)
    self.Power = CreatePowerBar(self)
end


Rainrider 02-13-18 04:10 PM

You are placing the health and power bars on top of each other.


All times are GMT -6. The time now is 10:28 PM.

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