From 0b3e9df0d94841ddb160eccbc5750b0e68d6d75b Mon Sep 17 00:00:00 2001 From: shagu Date: Sun, 16 Apr 2017 16:07:41 +0200 Subject: [PATCH] unitframes: add 40y-rangecheck --- api/api.lua | 43 ++++++++++++++++++++++++++++++++++++++++++ api/config.lua | 2 ++ api/unitframes.lua | 2 +- env/locales_deDE.lua | 7 +++++++ env/locales_enUS.lua | 7 +++++++ env/locales_frFR.lua | 7 +++++++ env/locales_ruRU.lua | 7 +++++++ env/locales_zhCN.lua | 7 +++++++ modules/gui.lua | 2 ++ modules/rangecheck.lua | 31 ++++++++++++++++++++++++++++++ pfUI.toc | 1 + 11 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 modules/rangecheck.lua diff --git a/api/api.lua b/api/api.lua index 6a14d683..2ff60792 100644 --- a/api/api.lua +++ b/api/api.lua @@ -1,6 +1,7 @@ pfUI.api = { } pfUI.api._G = getfenv(0) local _G = getfenv(0) + -- [ strsplit ] -- Splits a string using a delimiter. -- 'delimiter' [string] characters that will be interpreted as delimiter @@ -14,6 +15,48 @@ function pfUI.api.strsplit(delimiter, subject) return unpack(fields) end +-- [ UnitInRange ] +-- Returns whether a party/raid member is nearby. It uses spells with a distance of around 40 yards. +-- unit [string] A unit to query (string, unitID) +-- return: [bool] "1" if in range otherwise "nil" +local RangeCache = {} +function pfUI.api.UnitInRange(unit) + if not UnitExists(unit) or not UnitIsVisible(unit) then + return nil + end + + if CheckInteractDistance(unit, 4) then + return 1 + else if not pfUI.rangecheck or not pfUI.rangecheck.slot then + return nil + else + -- Extended Range Check + if not RangeCache[unit] or RangeCache[unit].time + pfUI.rangecheck.interval < GetTime() then + RangeCache[unit] = {} + RangeCache[unit].time = GetTime() + + local noswitch = true + if not UnitIsUnit("target", unit) then + TargetUnit(unit) + noswitch = false + end + + if IsActionInRange(pfUI.rangecheck.slot) == 1 then + RangeCache[unit].range = 1 + else + RangeCache[unit].range = nil + end + + if not noswitch then + TargetLastTarget() + end + end + + return RangeCache[unit].range + end + end +end + -- [ strvertical ] -- Creates vertical text using linebreaks. Multibyte char friendly. -- 'str' [string] String to columnize. diff --git a/api/config.lua b/api/config.lua index 0b8271b6..2c1165fe 100644 --- a/api/config.lua +++ b/api/config.lua @@ -77,6 +77,8 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("unitframes", nil, "portraitalpha", "0.1") pfUI:UpdateConfig("unitframes", nil, "portraittexture", "1") pfUI:UpdateConfig("unitframes", nil, "layout", "default") + pfUI:UpdateConfig("unitframes", nil, "rangecheck", "0") + pfUI:UpdateConfig("unitframes", nil, "rangechecki", ".5") -- pfUI:UpdateConfig("unitframes", nil, "buff_size", "20") -- TODO migrate, deprecated -- pfUI:UpdateConfig("unitframes", nil, "debuff_size", "20") -- TODO migrate, deprecated diff --git a/api/unitframes.lua b/api/unitframes.lua index 27639062..99b243ca 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -170,7 +170,7 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick) end if this.config.faderange == "1" then - if CheckInteractDistance(this.label .. this.id, 4) or not UnitName(this.label .. this.id) then + if pfUI.api.UnitInRange(this.label .. this.id, 4) or not UnitName(this.label .. this.id) then if this:GetAlpha() ~= 1 then this:SetAlpha(1) if this.config.portrait == "bar" then diff --git a/env/locales_deDE.lua b/env/locales_deDE.lua index 3a080c32..8c0002d8 100644 --- a/env/locales_deDE.lua +++ b/env/locales_deDE.lua @@ -27,6 +27,13 @@ pfUI_locale["deDE"]["itemtypes"] = { ["INVTYPE_THROWN"] = "Wurfwaffe", } +pfUI_locale["deDE"]["rangecheck"] = { + ['PALADIN'] = "Heiliges Licht", + ['PRIEST'] = "Blitzheilung", + ['DRUID'] = "Heilende Berührung", + ['SHAMAN'] = "Welle der Heilung", +} + pfUI_locale["deDE"]["interrupts"] = { ["Schildhieb"] = true; ["Zuschlagen"] = true; diff --git a/env/locales_enUS.lua b/env/locales_enUS.lua index 6e1776ca..c4aadd91 100644 --- a/env/locales_enUS.lua +++ b/env/locales_enUS.lua @@ -27,6 +27,13 @@ pfUI_locale["enUS"]["itemtypes"] = { ["INVTYPE_THROWN"] = "Thrown", } +pfUI_locale["enUS"]["rangecheck"] = { + ['PALADIN'] = "Holy Light", + ['PRIEST'] = "Flash Heal", + ['DRUID'] = "Healing Touch", + ['SHAMAN'] = "Healing Wave", +} + pfUI_locale["enUS"]["interrupts"] = { ["Shield Bash"] = true; ["Pummel"] = true; diff --git a/env/locales_frFR.lua b/env/locales_frFR.lua index 4705bed5..5219dbda 100644 --- a/env/locales_frFR.lua +++ b/env/locales_frFR.lua @@ -27,6 +27,13 @@ pfUI_locale["frFR"]["itemtypes"] = { ["INVTYPE_THROWN"] = "Arme de jet", } +pfUI_locale["frFR"]["rangecheck"] = { + ['PALADIN'] = "Lumière sacrée", + ['PRIEST'] = "Soins rapides", + ['DRUID'] = "Toucher guérisseur", + ['SHAMAN'] = "Vague de soins", +} + pfUI_locale["frFR"]["interrupts"] = { ["Coup de bouclier"] = true; ["Volée de coups"] = true; diff --git a/env/locales_ruRU.lua b/env/locales_ruRU.lua index 3a222bc1..0b1b0db1 100644 --- a/env/locales_ruRU.lua +++ b/env/locales_ruRU.lua @@ -27,6 +27,13 @@ pfUI_locale["ruRU"]["itemtypes"] = { ["INVTYPE_THROWN"] = "Метательное", } +pfUI_locale["ruRU"]["rangecheck"] = { + ['PALADIN'] = "Свет небес", + ['PRIEST'] = "Быстрое исцеление", + ['DRUID'] = "Целительное прикосновение", + ['SHAMAN'] = "Волна исцеления", +} + pfUI_locale["ruRU"]["interrupts"] = { ["Удар щитом"] = true; ["Зуботычина"] = true; diff --git a/env/locales_zhCN.lua b/env/locales_zhCN.lua index b123e81b..21c8b2e8 100644 --- a/env/locales_zhCN.lua +++ b/env/locales_zhCN.lua @@ -27,6 +27,13 @@ pfUI_locale["zhCN"]["itemtypes"] = { ["INVTYPE_THROWN"] = "投掷武器", } +pfUI_locale["zhCN"]["rangecheck"] = { + ['PALADIN'] = "圣光术", + ['PRIEST'] = "快速治疗", + ['DRUID'] = "治疗之触", + ['SHAMAN'] = "治疗波", +} + pfUI_locale["zhCN"]["interrupts"] = { ["盾击"] = true; ["拳击"] = true; diff --git a/modules/gui.lua b/modules/gui.lua index 328a8ba9..06fe7647 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -864,6 +864,8 @@ pfUI:RegisterModule("gui", function () pfUI.gui:CreateConfig(pfUI.gui.uf, "Portrait Alpha", C.unitframes, "portraitalpha") pfUI.gui:CreateConfig(pfUI.gui.uf, "Enable 2D Portraits As Fallback", C.unitframes, "portraittexture", "checkbox") pfUI.gui:CreateConfig(pfUI.gui.uf, "Unit Frame Layout", C.unitframes, "layout", "dropdown", { "default", "tukui" }) + pfUI.gui:CreateConfig(pfUI.gui.uf, "Aggressive 40y-Range Check (Will break stuff)", C.unitframes, "rangecheck", "checkbox") + pfUI.gui:CreateConfig(pfUI.gui.uf, "40y-Range Check Interval", C.unitframes, "rangechecki") pfUI.gui:CreateConfig(pfUI.gui.uf, "Buff- And Debuff Indicators", nil, nil, "header") pfUI.gui:CreateConfig(pfUI.gui.uf, "Show Hots as Buff Indicators", C.unitframes, "show_hots", "checkbox") diff --git a/modules/rangecheck.lua b/modules/rangecheck.lua new file mode 100644 index 00000000..5fe994fe --- /dev/null +++ b/modules/rangecheck.lua @@ -0,0 +1,31 @@ +pfUI:RegisterModule("rangecheck", function () + local _,class = UnitClass("player") + + if C.unitframes.rangecheck == "0" then return end + + pfUI.rangecheck = CreateFrame("Frame", "pfRangecheck", UIParent) + pfUI.rangecheck.scanner = CreateFrame("GameTooltip", "pfRangecheckScanner", UIParent, "GameTooltipTemplate") + pfUI.rangecheck.scanner:SetOwner(pfUI.rangecheck, "ANCHOR_NONE") + + pfUI.rangecheck.slot = nil + pfUI.rangecheck.interval = C.unitframes.rangechecki + + pfUI.rangecheck:RegisterEvent("ACTIONBAR_SLOT_CHANGED") + pfUI.rangecheck:RegisterEvent("PLAYER_ENTERING_WORLD") + pfUI.rangecheck:SetScript("OnEvent", function() + pfUI.rangecheck.slot = nil + + for i=1,120 do + if pfUI.rangecheck.slot then return end + + pfUI.rangecheck.scanner:ClearLines() + pfUI.rangecheck.scanner:SetAction(i) + + if pfRangecheckScannerTextLeft1 and pfRangecheckScannerTextLeft1:GetText() then + if pfRangecheckScannerTextLeft1:GetText() == L["rangecheck"][class] then + pfUI.rangecheck.slot = i + end + end + end + end) +end) diff --git a/pfUI.toc b/pfUI.toc index b5d4dbdf..6e8c7c23 100644 --- a/pfUI.toc +++ b/pfUI.toc @@ -34,6 +34,7 @@ modules\pixelperfect.lua modules\hoverbind.lua modules\actionbar.lua modules\hunterbar.lua +modules\rangecheck.lua modules\chat.lua modules\addons.lua modules\minimap.lua