IMO, from a programmers PoV, the factory pattern should not apply here. There just are too many variables, for instance for my own UI:
- player has HP-bar, PP-bar, debuffs
- target has HP-bar, PP-bar, buffs & debuffs custom filtered
- tot has hp-bar, debuffs
- totot has hp-bar
- party members has HP-bar, PP-bar, debuffs, different Layout from player
- raid differs in 10/15/25 man setup
- arena is different yet again
all differ in size, alignments, position etc.
Factory would be nice if all UF-elements would be more or less the same otherwise you still end up with
Code:
Factory()
make_hp_bar()
if player then
position like so
elseif target then
mirror and position like so
elseif .. then
...
end
if player and shaman then
totems
elseif player and dk then
runes
end
-- etc etc etc
I've gone and made several styles like in the tut:
Code:
local function CreatePlayerStyle(self)
self.unit = "player"
func.placeFrame(self)
func.createStatusBar(self, "Health", true)
func.createStatusBar(self, "Power", true)
self.Health.frequentUpdates = true
self.Health.colorClass = true
self.Power.colorPower = true
func.addTag(self, self.Health, "[name]")
func.addTag(self, self.Health, "[eth:playerhp]")
func.addTag(self, self.Power, "[eth:smartpp]")
func.addTag(self, self.Health, "[eth:afk]")
func.createCastBar(self)
func.addPortrait(self)
-- func.addCombatText(self, self.Health)
func.checkTotems(self)
func.checkRunes(self)
--yeye, still streamlining this :P
self.Health.PostUpdate = func.addThreatColoring
self:RegisterEvent("PLAYER_REGEN_DISABLED", func.addInitThreatColoring)
self:RegisterEvent("PLAYER_REGEN_ENABLED", func.removeThreatColoring)
func.createDebuffs(self)
end
which build it all with generic functions:
Code:
--[[stripped documentation for size purpose]]--
func.createStatusBar = function(frame, barType, border)
local statusBar = CreateFrame("StatusBar", nil, frame)
statusBar:SetStatusBarTexture(media.images.statusbar)
statusBar:SetHeight(config[frame.unit].bars[barType].size.height)
statusBar:SetWidth(config[frame.unit].bars[barType].size.width)
statusBar:SetPoint(config[frame.unit].bars[barType].position.anchor,config[frame.unit].bars[barType].position.xOff,config[frame.unit].bars[barType].position.yOff)
local bgFrame = statusBar:CreateTexture(nil, "BACKGROUND")
bgFrame:SetTexture(media.images.statusbar)
bgFrame:SetAllPoints(statusBar)
bgFrame:SetAlpha(0.3)
if border == true then
local borderFrame = CreateFrame("Frame", nil, statusBar)
borderFrame:SetBackdrop(colors.backdrop_tab)
borderFrame:SetBackdropColor(unpack(colors.bgcolor))
borderFrame:SetBackdropBorderColor(unpack(colors.bgbordercolor))
borderFrame:SetPoint("TOPLEFT", statusBar, -3, 3)
borderFrame:SetPoint("BOTTOMRIGHT", statusBar, 2, -2)
end
frame[barType] = statusBar
frame[barType].bg = bgFrame
end
--[[stripped documentation for size purpose]]--
func.addTag = function(frame, parent, tag, font, size, outline, shadow)
local fString = parent:CreateFontString(nil, "OVERLAY")
fString:SetFont(font or config[frame.unit].texts[tag].font or media.font.normal,
size or config[frame.unit].texts[tag].size or media.font.size,
outline or config[frame.unit].texts[tag].outline or nil)
if shadow or config[frame.unit].texts[tag].shadow then
if shadow then
fString:SetShadowColor(unpack(shadow))
else
fString:SetShadowColor(unpack(config[frame.unit].texts[tag].shadow))
end
if config[frame.unit].texts[tag].shadowoff then
fString:SetShadowOffset(unpack(config[frame.unit].texts[tag].shadowoff))
end
end
fString:SetPoint(config[frame.unit].texts[tag].anchor, parent, config[frame.unit].texts[tag].xOff, config[frame.unit].texts[tag].yOff)
fString:SetJustifyH(config[frame.unit].texts[tag].justH)
frame:Tag(fString, tag)
end
which as you can see get it's data from a config (which I wont list here as we all know what an array with data looks like).
This makes code highly re-usable, and easily configurable.
Also, adding/disabling/removing or altering a style is much easier then when you have to go through your whole factory editing/altering for the new/old/whatnot unit.
Best of all: I can easily alter my UF's
without touching any code. All I have to do is just change my config.
files:
tags.lua
config.lua
func.lua
styles.lua
manage.lua
---
I'm not saying that the factory pattern is terribad and should not be used, I'm saying that when I want to make my own code reusable and easy, where quick changes are easily made, I would never use it. Since that's what every programmer should strive for (DRY, SRP) I'd discourage the use of the facory here to be honest.
Unfortunately I won't be around here again till tomorrow afternoon somewhere, but I'd be very interested in other people's PoV regarding this.
/salute
P.S.: yes, I know I'm relatively new to oUF compared to others around here, but I do have a solid programmers background
Oh yeah, and the above is still a WIP, so don't shoot the sometimes unlogical or unsimplified code