From 41282b3f68d3727e0330386bb4db91bcdf5be0cc Mon Sep 17 00:00:00 2001 From: snwflake Date: Fri, 16 Jul 2021 03:18:20 +0200 Subject: [PATCH] release add groupmember distance --- .github/workflows/master.yml | 2 +- CHANGELOG.md | 3 ++ README.md | 11 +++-- core.lua | 92 +++++++++++++++++++++++------------- snwDistance.toc | 2 +- 5 files changed, 72 insertions(+), 38 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index a4cc3e0..6e4e0e5 100755 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -34,7 +34,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ steps.set_env.outputs.version }} - release_name: Release snwDistance-${{ steps.set_env.outputs.version }} + release_name: snwDistance-${{ steps.set_env.outputs.version }} body: | ${{ steps.set_env.outputs.RELEASEBODY }} draft: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cb3567..4cb1408 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### Version v0.1.2: +- Add raidmember tracking + ### Version v0.1.1: - Remove debug code (recurring theme) diff --git a/README.md b/README.md index 09439ae..72b26c4 100755 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ # snwDistance for 7.3.5 (tauri alpha ptr testing) -Allows setting a position from your char +Allows setting a position with your character and automatically calculate the distance to your current location. +Also allows calculating distances between yourself and a groupmember in open-world. -![](https://i.imgur.com/sz8rzdp.png) +
-## Planned: +![](https://i.imgur.com/yQYWVkg.png) -- Add ability to get the distance between yourself and a raid-/groupmember (limitation by blizzard) \ No newline at end of file +
+ +**Tracking raid-/groupmember does not work in instances/battleground/arenas!** \ No newline at end of file diff --git a/core.lua b/core.lua index a2723eb..bd64c23 100755 --- a/core.lua +++ b/core.lua @@ -3,9 +3,10 @@ local ldb = nil local initialPos = {} local next = next -local text = nil +local text, cbRaid = nil local function getInitialPos() + if cbRaid then return end initialPos.y, initialPos.x = UnitPosition('Player') end @@ -14,28 +15,46 @@ local function resetPos() text:SetText('0') end +local function debugAbort(...) + resetPos() + print('|cffff8359snwDistance' .. ':|r ', ...) +end + local function calcDistance() - local y1, x1 = initialPos.y, initialPos.x + local y1, x1 + if cbRaid then + y1, x1 = UnitPosition('target') + if not y1 or not x1 then resetPos();return end + else + y1, x1 = initialPos.y, initialPos.x + end local y2, x2 = UnitPosition('player') text:SetText(string.format('%.3f', ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5)) end +local function isRaidTarget(f) + cbRaid = f:GetChecked() + if not cbRaid then + resetPos() + end +end + local frame = CreateFrame('frame', 'snwDistance', UIParent) local timeElapsed = 0 -frame:HookScript("OnUpdate", function(self, elapsed) +frame:HookScript('OnUpdate', function(self, elapsed) timeElapsed = timeElapsed + elapsed if timeElapsed > 0.5 then timeElapsed = 0 - if next(initialPos) ~= nil then + if next(initialPos) ~= nil or cbRaid then calcDistance() end end end) frame:SetBackdrop({ - bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background-Dark", - edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", + bgFile = 'Interface\\DialogFrame\\UI-DialogBox-Background-Dark', + edgeFile = 'Interface\\DialogFrame\\UI-DialogBox-Border', tile = true, tileSize = 16, edgeSize = 16, insets = {left = 1, right = 1, top = 1, bottom = 1} }) @@ -46,40 +65,49 @@ frame:SetSize(300, 150) frame:SetPoint('CENTER', UIParent, 'CENTER') frame:EnableMouse(true) frame:SetMovable(true) -frame:RegisterForDrag("LeftButton") -frame:SetScript("OnDragStart", function(self) self:StartMoving() end) -frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end) -frame:SetFrameStrata("DIALOG") +frame:RegisterForDrag('LeftButton') +frame:SetScript('OnDragStart', function(self) self:StartMoving() end) +frame:SetScript('OnDragStop', function(self) self:StopMovingOrSizing() end) +frame:SetFrameStrata('DIALOG') local tex = frame:CreateTexture(nil, 'DIALOG') tex:SetAllPoints(frame) tex:SetColorTexture(0, 0, 0, 0.5) -local pos1 = CreateFrame("button", nil, frame, "UIPanelButtonTemplate") +local pos1 = CreateFrame('button', nil, frame, 'UIPanelButtonTemplate') pos1:SetHeight(24) pos1:SetWidth(120) -pos1:SetPoint("BOTTOM", frame, "BOTTOMLEFT", 70, 40) -pos1:SetText("Set Pos") -pos1:SetScript("OnClick", getInitialPos) - -local clear = CreateFrame("button", nil, frame, "UIPanelButtonTemplate") +pos1:SetPoint('BOTTOM', frame, 'BOTTOMLEFT', 70, 40) +pos1:SetText('Set Pos') +pos1:SetScript('OnClick', getInitialPos) + +local cb = CreateFrame('CheckButton', nil, frame, 'UICheckButtonTemplate') +cb:SetHeight(24) +cb:SetWidth(24) +cb:SetPoint('BOTTOM', frame, 'BOTTOMLEFT', 145, 40) +cb.text:SetText(' Target Raidmember') +cb:SetScript('OnClick', isRaidTarget) + +local clear = CreateFrame('button', nil, frame, 'UIPanelButtonTemplate') clear:SetHeight(24) clear:SetWidth(120) -clear:SetPoint("BOTTOM", frame, "BOTTOMLEFT", 70, 10) -clear:SetText("Clear") -clear:SetScript("OnClick", resetPos) +clear:SetPoint('BOTTOM', frame, 'BOTTOMLEFT', 70, 10) +clear:SetText('Clear') +clear:SetScript('OnClick', resetPos) -local close = CreateFrame("button", nil, frame, "UIPanelButtonTemplate") +local close = CreateFrame('button', nil, frame, 'UIPanelButtonTemplate') close:SetHeight(24) close:SetWidth(120) -close:SetPoint("BOTTOM", frame, "BOTTOMRIGHT", -70, 10) -close:SetText("Close") -close:SetScript("OnClick", function(self) self:GetParent():Hide() end) +close:SetPoint('BOTTOM', frame, 'BOTTOMRIGHT', -70, 10) +close:SetText('Close') +close:SetScript('OnClick', function(self) self:GetParent():Hide() end) -text = frame:CreateFontString(frame, "OVERLAY", "GameFontNormalWTF2Outline") -text:SetPoint("TOP", 0, -30) +text = frame:CreateFontString(frame, 'OVERLAY', 'GameFontNormalWTF2Outline') +text:SetPoint('TOP', 0, -30) text:SetText('0') +frame:Hide() + local function toggleFrame() if frame:IsShown() then frame:Hide() @@ -90,12 +118,12 @@ end -- LDB ---------------------------------------------------------------------- -- do - local libLdb = LibStub("LibDataBroker-1.1") + local libLdb = LibStub('LibDataBroker-1.1') if libLdb then - ldb = libLdb:NewDataObject("snwDistance", { - type = "launcher", - label = "snwDistance", - icon = "Interface\\AddOns\\snwDistance\\media\\icon", + ldb = libLdb:NewDataObject('snwDistance', { + type = 'launcher', + label = 'snwDistance', + icon = 'Interface\\AddOns\\snwDistance\\media\\icon', }) function ldb.OnClick(self, button) @@ -108,9 +136,9 @@ frame:SetScript('OnEvent', function(self, e, ...) if e == 'ADDON_LOADED' then local args = ... if args ~= 'snwDistance' then return end - local icon = LibStub("LibDBIcon-1.0") + local icon = LibStub('LibDBIcon-1.0') if icon and ldb then - icon:Register("snwDistance", ldb, {}) + icon:Register('snwDistance', ldb, {}) end end end) \ No newline at end of file diff --git a/snwDistance.toc b/snwDistance.toc index 6640dfe..c9e2177 100755 --- a/snwDistance.toc +++ b/snwDistance.toc @@ -2,7 +2,7 @@ ## Title: snwDistance ## Author: snwflake -## Version: v0.1.1 +## Version: v0.1.2 embeds.xml