Allow size and range check features to be configured.
This also improves the range check to fall back to UnitInRange if no friendly spell is available
This commit is contained in:
@@ -16,6 +16,20 @@
|
||||
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
|
||||
local omif = select(2, ...)
|
||||
|
||||
local function RangeConfig()
|
||||
local _, class = UnitClass("player")
|
||||
if class == "SHAMAN" then
|
||||
return {
|
||||
friendly = "Healing Surge",
|
||||
enemy = "Lightning Bolt",
|
||||
fade = 0.2
|
||||
}
|
||||
else
|
||||
return {
|
||||
fade = 0.2
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local types = omif.GetModule("types")
|
||||
local UnitFrame = types.UnitFrame
|
||||
@@ -40,43 +54,59 @@ function HideBlizzardFrames()
|
||||
toggleFrame:Hide()
|
||||
end
|
||||
|
||||
function CreateRaidFrames(left, top, width, height)
|
||||
function CreateRaidFrames(left, top, config)
|
||||
local width = config.size.width
|
||||
local height = config.size.height
|
||||
local group = UnitGroup:new(left, top, width, height)
|
||||
for i=0,5 do
|
||||
for j=0,4 do
|
||||
local num = i*5 + j + 1
|
||||
local frame = UnitFrame:new("raid" .. num, width, height)
|
||||
local frame = UnitFrame:new("raid" .. num, config)
|
||||
group:AddUnitFrame(frame)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function CreatePartyFrames(left, top, width, height)
|
||||
function CreatePartyFrames(left, top, config)
|
||||
local width = config.size.width
|
||||
local height = config.size.height
|
||||
local group = UnitGroup:new(left, top, width, height)
|
||||
local player = UnitFrame:new("player", width, height, true)
|
||||
local player = UnitFrame:new("player", config)
|
||||
group:AddUnitFrame(player)
|
||||
for i=1,4 do
|
||||
local frame = UnitFrame:new("party" .. i, width, height, true)
|
||||
local frame = UnitFrame:new("party" .. i, config)
|
||||
group:AddUnitFrame(frame)
|
||||
end
|
||||
group:Sort()
|
||||
end
|
||||
|
||||
function CreateTargetFrames(left, top, width, height)
|
||||
local focus = UnitFrame:new("focus", width, height)
|
||||
function CreateTargetFrames(left, top, config)
|
||||
local width = config.size.width
|
||||
local height = config.size.height
|
||||
local focus = UnitFrame:new("focus", config)
|
||||
focus:SetPosition(left, top)
|
||||
local target = UnitFrame:new("target", width, height)
|
||||
local target = UnitFrame:new("target", config)
|
||||
target:SetPosition(left, top - height)
|
||||
for i=1,4 do
|
||||
local boss = UnitFrame:new("boss" .. i, width, height)
|
||||
local boss = UnitFrame:new("boss" .. i, config)
|
||||
boss:SetPosition(left, top-(i+1)*height)
|
||||
end
|
||||
end
|
||||
|
||||
function CreateFrames()
|
||||
CreatePartyFrames(0, -290, 110, 45)
|
||||
CreateRaidFrames(0, -290, 110, 45)
|
||||
CreateTargetFrames(110*3+50, -245, 110, 45)
|
||||
config = {
|
||||
size = {
|
||||
width = 110,
|
||||
height = 45,
|
||||
},
|
||||
range = RangeConfig(),
|
||||
hideInRaid = true,
|
||||
}
|
||||
|
||||
CreatePartyFrames(0, -290, config)
|
||||
config.hideInRaid = false
|
||||
CreateRaidFrames(0, -290, config)
|
||||
CreateTargetFrames(110*3+50, -245, config)
|
||||
HideBlizzardFrames()
|
||||
end
|
||||
omif.SetEventHandler("OMICRON_LOADING", CreateFrames)
|
||||
|
@@ -44,15 +44,25 @@ local colors = {
|
||||
white = {1.0, 1.0, 1.0}
|
||||
}
|
||||
|
||||
function UnitFrame:Init(unit, width, height, hideInRaid)
|
||||
function UnitFrame:Init(unit, config)
|
||||
local width = config.size.width
|
||||
local height = config.size.height
|
||||
|
||||
self.unit = unit
|
||||
self.hideInRaid = hideInRaid or false
|
||||
self.hideInRaid = config.hideInRaid
|
||||
|
||||
self.rangeFriendly = config.range.friendly
|
||||
self.rangeEnemy = config.range.enemy
|
||||
self.rangeFade = config.range.fade
|
||||
|
||||
local secure = self:CreateSecureFrame(width, height)
|
||||
secure:Hide()
|
||||
|
||||
self.hp = StatusBar:new(self, width, height, 0, true)
|
||||
self.power = StatusBar:new(self, width, 6, 2, false)
|
||||
self.power:Hide()
|
||||
self.auras = AuraList:new(self)
|
||||
|
||||
local overlays = CreateFrame("Frame", nil, secure)
|
||||
overlays:SetFrameStrata("MEDIUM")
|
||||
overlays:SetFrameLevel(100)
|
||||
@@ -118,16 +128,44 @@ function UnitFrame:StopRangeTicker()
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns
|
||||
-- true if the unit is in range
|
||||
-- false if the unit is not in range
|
||||
-- nil if it could not be determined
|
||||
function UnitFrame:IsInRange()
|
||||
local unit = self.unit
|
||||
local friendlySpell = self.rangeFriendly
|
||||
local enemySpell = self.rangeEnemy
|
||||
|
||||
-- Prefer to use configured spells
|
||||
if friendlySpell and UnitCanAssist("player", unit) then
|
||||
return IsSpellInRange(friendlySpell, unit) == 1
|
||||
elseif enemySpell and UnitCanAttack("player", unit) then
|
||||
return IsSpellInRange(enemySpell, unit) == 1
|
||||
end
|
||||
|
||||
-- Fall back to raid/party only range check
|
||||
local inRange, checkedRange = UnitInRange(unit)
|
||||
if checkedRange then
|
||||
return inRange
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
function UnitFrame:UpdateRange()
|
||||
local unit = self.unit
|
||||
if UnitIsDead(unit) then
|
||||
|
||||
if UnitIsDeadOrGhost(unit) then
|
||||
self.secureFrame:SetAlpha(1.0)
|
||||
return
|
||||
end
|
||||
|
||||
local inRange = self:IsInRange()
|
||||
if inRange or inRange == nil then
|
||||
self.secureFrame:SetAlpha(1.0)
|
||||
elseif not UnitIsFriend("player", unit) and IsSpellInRange("Lightning Bolt", unit) ~= 1 then
|
||||
self.secureFrame:SetAlpha(0.2)
|
||||
elseif UnitIsFriend("player", unit) and IsSpellInRange("Healing Surge", unit) ~= 1 then
|
||||
self.secureFrame:SetAlpha(0.2)
|
||||
else
|
||||
self.secureFrame:SetAlpha(1.0)
|
||||
self.secureFrame:SetAlpha(self.rangeFade)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user