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:
2023-04-01 01:17:54 +02:00
parent 825738a040
commit e72c4b3e3f
2 changed files with 88 additions and 20 deletions

View File

@@ -16,6 +16,20 @@
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>. -- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
local omif = select(2, ...) 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 types = omif.GetModule("types")
local UnitFrame = types.UnitFrame local UnitFrame = types.UnitFrame
@@ -40,43 +54,59 @@ function HideBlizzardFrames()
toggleFrame:Hide() toggleFrame:Hide()
end 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) local group = UnitGroup:new(left, top, width, height)
for i=0,5 do for i=0,5 do
for j=0,4 do for j=0,4 do
local num = i*5 + j + 1 local num = i*5 + j + 1
local frame = UnitFrame:new("raid" .. num, width, height) local frame = UnitFrame:new("raid" .. num, config)
group:AddUnitFrame(frame) group:AddUnitFrame(frame)
end end
end 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 group = UnitGroup:new(left, top, width, height)
local player = UnitFrame:new("player", width, height, true) local player = UnitFrame:new("player", config)
group:AddUnitFrame(player) group:AddUnitFrame(player)
for i=1,4 do for i=1,4 do
local frame = UnitFrame:new("party" .. i, width, height, true) local frame = UnitFrame:new("party" .. i, config)
group:AddUnitFrame(frame) group:AddUnitFrame(frame)
end end
group:Sort() group:Sort()
end end
function CreateTargetFrames(left, top, width, height) function CreateTargetFrames(left, top, config)
local focus = UnitFrame:new("focus", width, height) local width = config.size.width
local height = config.size.height
local focus = UnitFrame:new("focus", config)
focus:SetPosition(left, top) focus:SetPosition(left, top)
local target = UnitFrame:new("target", width, height) local target = UnitFrame:new("target", config)
target:SetPosition(left, top - height) target:SetPosition(left, top - height)
for i=1,4 do 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) boss:SetPosition(left, top-(i+1)*height)
end end
end end
function CreateFrames() function CreateFrames()
CreatePartyFrames(0, -290, 110, 45) config = {
CreateRaidFrames(0, -290, 110, 45) size = {
CreateTargetFrames(110*3+50, -245, 110, 45) 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() HideBlizzardFrames()
end end
omif.SetEventHandler("OMICRON_LOADING", CreateFrames) omif.SetEventHandler("OMICRON_LOADING", CreateFrames)

View File

@@ -44,15 +44,25 @@ local colors = {
white = {1.0, 1.0, 1.0} 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.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) local secure = self:CreateSecureFrame(width, height)
secure:Hide() secure:Hide()
self.hp = StatusBar:new(self, width, height, 0, true) self.hp = StatusBar:new(self, width, height, 0, true)
self.power = StatusBar:new(self, width, 6, 2, false) self.power = StatusBar:new(self, width, 6, 2, false)
self.power:Hide() self.power:Hide()
self.auras = AuraList:new(self) self.auras = AuraList:new(self)
local overlays = CreateFrame("Frame", nil, secure) local overlays = CreateFrame("Frame", nil, secure)
overlays:SetFrameStrata("MEDIUM") overlays:SetFrameStrata("MEDIUM")
overlays:SetFrameLevel(100) overlays:SetFrameLevel(100)
@@ -118,16 +128,44 @@ function UnitFrame:StopRangeTicker()
end end
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() function UnitFrame:UpdateRange()
local unit = self.unit 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) 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 else
self.secureFrame:SetAlpha(1.0) self.secureFrame:SetAlpha(self.rangeFade)
end end
end end