Quantcast

-- oUF_Simple: core/spawn
-- zork, 2016

-----------------------------
-- Variables
-----------------------------

local A, L = ...
local oUF = L.oUF or oUF

-----------------------------
-- Load HealComm
-----------------------------
LibStub("LibHealComm-4.0"):PLAYER_LOGIN()

-----------------------------
-- Register Style
-----------------------------

if L.F.CreatePlayerStyle then oUF:RegisterStyle(A.."Player", L.F.CreatePlayerStyle) end
if L.F.CreateTargetStyle then oUF:RegisterStyle(A.."Target", L.F.CreateTargetStyle) end
if L.F.CreateTargetTargetStyle then oUF:RegisterStyle(A.."TargetTarget", L.F.CreateTargetTargetStyle) end
if L.F.CreatePetStyle then oUF:RegisterStyle(A.."Pet", L.F.CreatePetStyle) end
if L.F.CreateFocusStyle then oUF:RegisterStyle(A.."Focus", L.F.CreateFocusStyle) end
if L.F.CreateMouseoverStyle then oUF:RegisterStyle(A.."Mouseover", L.F.CreateMouseoverStyle) end
if L.F.CreatePartyStyle then oUF:RegisterStyle(A.."Party", L.F.CreatePartyStyle) end
if L.F.CreateBossStyle then oUF:RegisterStyle(A.."Boss", L.F.CreateBossStyle) end
if L.F.CreateNamePlateStyle then oUF:RegisterStyle(A.."Nameplate",L.F.CreateNamePlateStyle) end
if L.F.CreateRaidStyle then oUF:RegisterStyle(A.."Raid", L.F.CreateRaidStyle) end
if L.F.CreateArenaStyle then oUF:RegisterStyle(A.."Arena", L.F.CreateArenaStyle) end
if L.F.CreateMainTankStyle then oUF:RegisterStyle(A.."MainTank", L.F.CreateMainTankStyle) end
if L.F.CreateMainAssistStyle then oUF:RegisterStyle(A.."MainAssist", L.F.CreateMainAssistStyle) end

-----------------------------
-- Spawn Units
-----------------------------

--spawn player
if L.F.CreatePlayerStyle then
  oUF:SetActiveStyle(A.."Player")
  local player = oUF:Spawn("player", A.."Player")
  --show/hide the frame on a given state driver
  if player.cfg.frameVisibility then
    player:Disable()
    --frameVisibility needed for rLib drag and drop
    player.frameVisibility = player.cfg.frameVisibility
    RegisterStateDriver(player, "visibility", player.cfg.frameVisibility)
  end
  --OnShow fader
  if player.cfg.fader then
    rLib:CreateFrameFader(player, player.cfg.fader)
  end
end

--spawn target
if L.F.CreateTargetStyle then
  oUF:SetActiveStyle(A.."Target")
  local target = oUF:Spawn("target", A.."Target")
  --OnShow fader
  if target.cfg.fader then
    rLib:CreateFrameFader(target, target.cfg.fader)
  end
end

--spawn targettarget
if L.F.CreateTargetTargetStyle then
  oUF:SetActiveStyle(A.."TargetTarget")
  oUF:Spawn("targettarget", A.."TargetTarget")
end

--spawn pet
if L.F.CreatePetStyle then
  oUF:SetActiveStyle(A.."Pet")
  local pet = oUF:Spawn("pet", A.."Pet")
  --show/hide the frame on a given state driver
  if pet.cfg.frameVisibility then
    pet:Disable()
    --frameVisibility needed for rLib drag and drop
    pet.frameVisibility = pet.cfg.frameVisibility
    RegisterStateDriver(pet, "visibility", pet.cfg.frameVisibility)
  end
  --OnShow fader
  if pet.cfg.fader then
    rLib:CreateFrameFader(pet, pet.cfg.fader)
  end
end

--spawn focus
if L.F.CreateFocusStyle then
  oUF:SetActiveStyle(A.."Focus")
  oUF:Spawn("focus", A.."Focus")
end

--spawn mouseover
if L.F.CreateMouseoverStyle then
  oUF:SetActiveStyle(A.."Mouseover")
  oUF:Spawn("mouseover", A.."Mouseover")
end

--spawn party
if L.F.CreatePartyStyle then
  oUF:SetActiveStyle(A.."Party")
  oUF:SpawnHeader(
    A.."PartyHeader",
    L.C.party.setup.template,
    L.C.party.setup.visibility,
    "showPlayer", L.C.party.setup.showPlayer,
    "showSolo",   L.C.party.setup.showSolo,
    "showParty",  L.C.party.setup.showParty,
    "showRaid",   L.C.party.setup.showRaid,
    "point",      L.C.party.setup.point,
    "xOffset",    L.C.party.setup.xOffset,
    "yOffset",    L.C.party.setup.yOffset,
    "oUF-initialConfigFunction", ([[
      self:SetWidth(%d)
      self:SetHeight(%d)
      self:GetParent():SetScale(%f)
    ]]):format(L.C.party.size[1], L.C.party.size[2], L.C.party.scale)
  ):SetPoint(unpack(L.C.party.point))
end

--spawn boss frames
if L.F.CreateBossStyle then
  oUF:SetActiveStyle(A.."Boss")
  local boss = {}
  for i = 1, MAX_BOSS_FRAMES do
    boss[i] = oUF:Spawn("boss"..i, A.."Boss"..i)
    if (i == 1) then
      boss[i]:SetPoint(unpack(L.C.boss.point))
    else
      boss[i]:SetPoint(L.C.boss.setup.point, boss[i-1], L.C.boss.setup.relativePoint, L.C.boss.setup.xOffset, L.C.boss.setup.yOffset)
    end
  end
end

--spawn nameplates
if L.F.CreateNamePlateStyle then
  oUF:SetActiveStyle(A.."Nameplate")
  oUF:SpawnNamePlates(A, L.C.NamePlateCallback, L.C.NamePlateCVars)
end

--spawn raid
if L.F.CreateRaidStyle then
  oUF:SetActiveStyle(A.."Raid")
  for i=1, NUM_RAID_GROUPS do
    oUF:SpawnHeader(
      A.."RaidHeader"..i,
      L.C.raid.setup.template,
      L.C.raid.setup.visibility,
      "showPlayer", L.C.raid.setup.showPlayer,
      "showSolo",   L.C.raid.setup.showSolo,
      "showParty",  L.C.raid.setup.showParty,
      "showRaid",   L.C.raid.setup.showRaid,
      "point",      L.C.raid.setup.point,
      "xOffset",    L.C.raid.setup.xOffset,
      "yOffset",    L.C.raid.setup.yOffset,
      "groupFilter",    tostring(i),
      "unitsPerColumn", 5,
      "oUF-initialConfigFunction", ([[
        self:SetWidth(%d)
        self:SetHeight(%d)
        self:GetParent():SetScale(%f)
      ]]):format(L.C.raid.size[1], L.C.raid.size[2], L.C.raid.scale)
    ):SetPoint(unpack(L.C.raid.points[i])) --config needs to provide 8 point tables, one for each raid group
  end
end

--spawn maintank
if L.F.CreateMainTankStyle then
  oUF:SetActiveStyle(A.."MainTank")
  oUF:SpawnHeader(
    A.."RaidHeader".."MainTank",
    L.C.maintank.setup.template,
    L.C.maintank.setup.visibility,
    "showPlayer", L.C.maintank.setup.showPlayer,
    "showSolo",   L.C.maintank.setup.showSolo,
    "showParty",  L.C.maintank.setup.showParty,
    "showRaid",   L.C.maintank.setup.showRaid,
    "point",      L.C.maintank.setup.point,
    "xOffset",    L.C.maintank.setup.xOffset,
    "yOffset",    L.C.maintank.setup.yOffset,
    "groupFilter",    "MAINTANK",
    "unitsPerColumn", 5,
    "oUF-initialConfigFunction", ([[
      self:SetWidth(%d)
      self:SetHeight(%d)
      self:GetParent():SetScale(%f)
    ]]):format(L.C.maintank.size[1], L.C.maintank.size[2], L.C.maintank.scale)
  ):SetPoint(unpack(L.C.maintank.point))
end

--spawn mainassist
if L.F.CreateMainAssistStyle then
  oUF:SetActiveStyle(A.."MainAssist")
  oUF:SpawnHeader(
    A.."RaidHeader".."MainAssist",
    L.C.mainassist.setup.template,
    L.C.mainassist.setup.visibility,
    "showPlayer", L.C.mainassist.setup.showPlayer,
    "showSolo",   L.C.mainassist.setup.showSolo,
    "showParty",  L.C.mainassist.setup.showParty,
    "showRaid",   L.C.mainassist.setup.showRaid,
    "point",      L.C.mainassist.setup.point,
    "xOffset",    L.C.mainassist.setup.xOffset,
    "yOffset",    L.C.mainassist.setup.yOffset,
    "groupFilter",    "MAINASSIST",
    "unitsPerColumn", 5,
    "oUF-initialConfigFunction", ([[
      self:SetWidth(%d)
      self:SetHeight(%d)
      self:GetParent():SetScale(%f)
    ]]):format(L.C.mainassist.size[1], L.C.mainassist.size[2], L.C.mainassist.scale)
  ):SetPoint(unpack(L.C.mainassist.point))
end

--spawn arena frames
if L.F.CreateArenaStyle then
  oUF:SetActiveStyle(A.."Arena")
  local arena = {}
  for i = 1, 5 do
    arena[i] = oUF:Spawn("arena"..i, A.."Arena"..i)
    if (i == 1) then
      arena[i]:SetPoint(unpack(L.C.arena.point))
    else
      arena[i]:SetPoint(L.C.arena.setup.point, arena[i-1], L.C.arena.setup.relativePoint, L.C.arena.setup.xOffset, L.C.arena.setup.yOffset)
    end
  end
  SetCVar("showArenaEnemyFrames", 0)
end